Skip to content

Commit bdd1be2

Browse files
authored
Add ruff-specific rules (RUF) (#558)
1 parent 6b1454d commit bdd1be2

File tree

18 files changed

+41
-26
lines changed

18 files changed

+41
-26
lines changed

examples/evaluation/langchain_trulens_full.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@
455455
"\n",
456456
"# note that token & cost data collection is currently broken with AzureOpenAI\n",
457457
"\n",
458-
"columns_to_keep = feedback_columns + [\n",
458+
"columns_to_keep = [\n",
459+
" *feedback_columns,\n",
459460
" \"record_id\",\n",
460461
" \"input\",\n",
461462
" \"output\",\n",
@@ -490,7 +491,7 @@
490491
"import numpy as np\n",
491492
"import pandas as pd\n",
492493
"\n",
493-
"tests = feedback_columns + [\"latency\", \"total_tokens\", \"total_cost\"]\n",
494+
"tests = [*feedback_columns, \"latency\", \"total_tokens\", \"total_cost\"]\n",
494495
"\n",
495496
"results = pd.DataFrame(\n",
496497
" columns=[\"records\", \"mean\", \"median\", \"95th_percentile\", \"99th_percentile\"]\n",

examples/evaluation/tru_download.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
print(f"Downloading data for {app_id}...")
1111
df_records, feedback_columns = tru.get_records_and_feedback([app_id])
1212

13-
columns_to_keep = feedback_columns + [
13+
columns_to_keep = [
14+
*feedback_columns,
1415
"record_id",
1516
"input",
1617
"output",

examples/notebooks/advancedRAG.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
"Context: {context}\n",
223223
"Question: {question}\n",
224224
"Your answer:\n",
225-
"\"\"\" # noqa: E501\n",
225+
"\"\"\"\n",
226226
"prompt = ChatPromptTemplate.from_template(prompt_template)\n",
227227
"\n",
228228
"questions = [\n",

examples/notebooks/astradb.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@
521521
"\n",
522522
"QUESTION: {question}\n",
523523
"\n",
524-
"YOUR ANSWER:\"\"\" # noqa: E501\n",
524+
"YOUR ANSWER:\"\"\"\n",
525525
"\n",
526526
"philo_prompt = ChatPromptTemplate.from_template(philo_template)\n",
527527
"\n",

examples/notebooks/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def try_delete_with_backoff(collection: str, sleep=1, max_tries=2):
3030
try:
3131
logging.info(f"deleting collection {collection}")
3232
response = client.delete_collection(collection)
33-
logging.info(f"delete collection {collection} response: {str(response)}")
33+
logging.info(f"delete collection {collection} response: {response!s}")
3434
except Exception as e:
3535
max_tries -= 1
3636
if max_tries < 0:

examples/notebooks/langchain_evaluation.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@
318318
"Context: {context}\n",
319319
"Question: {question}\n",
320320
"Your answer:\n",
321-
"\"\"\" # noqa: E501\n",
321+
"\"\"\"\n",
322322
"prompt = ChatPromptTemplate.from_template(prompt_template)\n",
323323
"model = ChatOpenAI()\n",
324324
"\n",
@@ -408,13 +408,13 @@
408408
" \"What motivates the narrator, Montresor, to seek revenge against Fortunato?\",\n",
409409
" \"What are the major themes in this story?\",\n",
410410
" \"What is the significance of the story taking place during the carnival season?\",\n",
411-
" \"What literary techniques does Poe use to create suspense and tension in the story?\", # noqa: E501\n",
411+
" \"What literary techniques does Poe use to create suspense and tension in the story?\",\n",
412412
"]\n",
413413
"\n",
414414
"eval_answers = [\n",
415415
" \"Montresor is insulted by Lenora and seeks revenge.\", # Incorrect Answer\n",
416416
" \"The major themes are happiness and trustworthiness.\", # Incorrect Answer\n",
417-
" \"The carnival season is a time of celebration and merriment, which contrasts with the sinister events of the story.\", # noqa: E501\n",
417+
" \"The carnival season is a time of celebration and merriment, which contrasts with the sinister events of the story.\",\n",
418418
" \"Poe uses foreshadowing, irony, and symbolism to create suspense and tension.\",\n",
419419
"]\n",
420420
"\n",

libs/e2e-tests/e2e_tests/langchain/test_astra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def test_basic_metadata_filtering_no_vector(vectorstore: AstraDBVectorStore):
193193
else:
194194
pytest.fail(
195195
f"Should have thrown ValueError with UNSUPPORTED_FILTER_OPERATION "
196-
f"but it was {e}" # noqa: E501
196+
f"but it was {e}"
197197
)
198198

199199

libs/e2e-tests/e2e_tests/langchain/test_compatibility_rag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,4 +499,4 @@ def test_chat(chat, request, record_property):
499499
record_langsmith_sharelink(run_id, record_property)
500500
assert "Syracuse" in str(
501501
response.content
502-
), f"Expected Syracuse in the answer but got: {str(response.content)}"
502+
), f"Expected Syracuse in the answer but got: {response.content!s}"

libs/e2e-tests/e2e_tests/test_utils/astradb_vector_store_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def try_delete_with_backoff(collection: str, sleep=1, max_tries=5):
229229
response = AstraDBVectorStoreHandler.default_astra_client.delete_collection(
230230
collection
231231
)
232-
logging.info(f"delete collection {collection} response: {str(response)}")
232+
logging.info(f"delete collection {collection} response: {response!s}")
233233
except Exception as e:
234234
max_tries -= 1
235235
if max_tries < 0:

libs/knowledge-graph/ragstack_knowledge_graph/traverse.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@
66
from cassio.config import check_resolve_keyspace, check_resolve_session
77

88

9-
class Node(NamedTuple):
9+
class _Node(NamedTuple):
1010
name: str
1111
type: str
12-
properties: Dict[str, Any] = {}
12+
properties: Dict[str, Any]
13+
14+
15+
class Node(_Node):
16+
__slots__ = ()
17+
18+
def __new__(cls, name, type, properties=None):
19+
if properties is None:
20+
properties = {}
21+
return super().__new__(cls, name, type, properties)
1322

1423
def __repr__(self):
1524
return f"{self.name} ({self.type})"
@@ -64,7 +73,7 @@ def _prepare_edge_query(
6473
WHERE {edge_source_name} = ?
6574
AND {edge_source_type} = ?"""
6675
if edge_filters:
67-
query = "\n AND ".join([query] + edge_filters)
76+
query = "\n AND ".join([query, *edge_filters])
6877
return session.prepare(query)
6978

7079

0 commit comments

Comments
 (0)