Skip to content

Commit 6b4f9be

Browse files
authored
Add ruff rules for self (#572)
1 parent c969efc commit 6b4f9be

File tree

11 files changed

+23
-25
lines changed

11 files changed

+23
-25
lines changed

examples/notebooks/langchain_dynamic_fewshot_SQL.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
"COMMIT;\n",
191191
"\"\"\"\n",
192192
"\n",
193-
"with db._engine.begin() as conn:\n",
193+
"with db._engine.begin() as conn: # noqa: SLF001\n",
194194
" conn.connection.executescript(PETS_SQL)"
195195
]
196196
},

libs/colbert/ragstack_colbert/cassandra_database.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def from_session(
6868
table_name: Optional[str] = "colbert",
6969
):
7070
instance = super().__new__(cls)
71-
instance._initialize(session=session, keyspace=keyspace, table_name=table_name)
71+
instance._initialize(session=session, keyspace=keyspace, table_name=table_name) # noqa: SLF001
7272
return instance
7373

7474
def _initialize(

libs/e2e-tests/e2e_tests/conftest.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ def pytest_runtest_makereport(item, call):
138138
import traceback
139139

140140
traceback.print_exception(
141-
call.excinfo._excinfo[0],
142-
call.excinfo._excinfo[1],
143-
call.excinfo._excinfo[2],
141+
call.excinfo.type, call.excinfo.value, call.excinfo.tb
144142
)
145143
except Exception: # noqa: BLE001
146144
logging.warning("Failed to print stacktrace", exc_info=True)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_wrong_connection_parameters(environment: Environment):
109109

110110
# This is expected to be a valid endpoint,
111111
# because we want to test an AUTHENTICATION error
112-
api_endpoint = environment.vectorstore._astra_db.base_url
112+
api_endpoint = environment.vectorstore._astra_db.base_url # noqa: SLF001
113113
try:
114114
print("api_endpoint:", api_endpoint)
115115
AstraDBVectorStore(

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ def get_current_deletions(self):
5757
"""
5858
Returns the number of ongoing deletions.
5959
"""
60-
return self.max_workers - self.semaphore._value
60+
return self.max_workers - self.semaphore._value # noqa: SLF001
6161

6262
def await_ongoing_deletions_completed(self):
6363
"""
6464
Blocks until all ongoing deletions are completed.
6565
"""
66-
while self.semaphore._value != self.max_workers:
66+
pending_deletions = self.max_workers - self.semaphore._value # noqa: SLF001
67+
while pending_deletions >= 0:
6768
logging.debug(
68-
"%s deletions still running, waiting to complete",
69-
self.max_workers - self.semaphore._value,
69+
"%s deletions still running, waiting to complete", pending_deletions
7070
)
7171
time.sleep(1)
7272
return

libs/knowledge-graph/ragstack_knowledge_graph/traverse.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ def handle_result(rows, source_distance: int, request: ResponseFuture):
149149
request.start_fetching_next_page()
150150
else:
151151
with condition:
152-
if request._req_id in pending:
153-
pending.remove(request._req_id)
152+
req_id = request._req_id # noqa: SLF001
153+
if req_id in pending:
154+
pending.remove(req_id)
154155
if len(pending) == 0:
155156
condition.notify()
156157

@@ -178,7 +179,7 @@ def fetch_relationships(distance: int, source: Node) -> None:
178179
request: ResponseFuture = session.execute_async(
179180
query, (source.name, source.type)
180181
)
181-
pending.add(request._req_id)
182+
pending.add(request._req_id) # noqa: SLF001
182183
request.add_callbacks(
183184
handle_result,
184185
handle_error,

libs/langchain/ragstack_langchain/colbert/colbert_vector_store.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ def from_texts(
244244
) -> CVS:
245245
"""Return VectorStore initialized from texts and embeddings."""
246246

247-
instance = super().__new__(cls)
248-
instance._initialize(database=database, embedding_model=embedding_model)
247+
instance = cls(database=database, embedding_model=embedding_model, **kwargs)
249248
instance.add_texts(texts=texts, metadatas=metadatas)
250249
return instance
251250

@@ -260,8 +259,7 @@ async def afrom_texts(
260259
**kwargs: Any,
261260
) -> CVS:
262261
"""Return VectorStore initialized from texts and embeddings."""
263-
instance = super().__new__(cls)
264-
instance._initialize(database=database, embedding_model=embedding_model)
262+
instance = cls(database=database, embedding_model=embedding_model, **kwargs)
265263
await instance.aadd_texts(
266264
texts=texts, metadatas=metadatas, concurrent_inserts=concurrent_inserts
267265
)

libs/ragulate/ragstack_ragulate/cli_commands/run.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ def call_run(config_file: str, **kwargs):
5555

5656
logger.debug("Found these ingest pipelines:")
5757
for ingest_pipeline in ingest_pipelines:
58-
logger.debug(f"\t{ingest_pipeline._key()}")
58+
logger.debug(f"\t{ingest_pipeline.key()}")
5959

6060
ingest_pipelines = list(set(ingest_pipelines))
6161

6262
logger.debug("Narrowed down to these ingest pipelines:")
6363
for ingest_pipeline in ingest_pipelines:
64-
logger.debug(f"\t{ingest_pipeline._key()}")
64+
logger.debug(f"\t{ingest_pipeline.key()}")
6565

6666
logger.debug("Found these query pipelines:")
6767
for query_pipeline in query_pipelines:
68-
logger.debug(f"\t{query_pipeline._key()}")
68+
logger.debug(f"\t{query_pipeline.key()}")
6969

7070
query_pipelines = list(set(query_pipelines))
7171

7272
logger.debug("Narrowed down to these query pipelines:")
7373
for query_pipeline in query_pipelines:
74-
logger.debug(f"\t{query_pipeline._key()}")
74+
logger.debug(f"\t{query_pipeline.key()}")
7575

7676
for ingest_pipeline in ingest_pipelines:
7777
ingest_pipeline.ingest()

libs/ragulate/ragstack_ragulate/pipelines/base_pipeline.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def get_method(self):
107107
def dataset_names(self) -> List[str]:
108108
return [d.name for d in self.datasets]
109109

110-
def _key(self) -> str:
110+
def key(self) -> str:
111111
key_parts = [
112112
self.pipeline_type,
113113
self.script_path,
@@ -119,8 +119,8 @@ def _key(self) -> str:
119119

120120
def __eq__(self, other):
121121
if isinstance(other, BasePipeline):
122-
return self._key() == other._key()
122+
return self.key() == other.key()
123123
return False
124124

125125
def __hash__(self):
126-
return hash(self._key())
126+
return hash(self.key())

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ select = [
9999
"RSE",
100100
"RUF",
101101
"SIM",
102+
"SLF",
102103
"SLOT",
103104
"T10",
104105
"T20",

scripts/generate-testspace-report.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def cdata(text: str) -> str:
7272
return f"<![CDATA[{text}]]>"
7373

7474

75-
xml.etree.ElementTree._escape_cdata = unsafe_escape_data
75+
xml.etree.ElementTree._escape_cdata = unsafe_escape_data # noqa: SLF001
7676

7777

7878
def main(report_type: str, input_file: str, output_file: str):

0 commit comments

Comments
 (0)