Skip to content

Commit 264a258

Browse files
authored
Add ruff rules for pyupgrade (#546)
1 parent 50d23ed commit 264a258

File tree

13 files changed

+25
-22
lines changed

13 files changed

+25
-22
lines changed

libs/knowledge-graph/ragstack_knowledge_graph/knowledge_schema.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,10 @@ def validate_graph_document(self, document: GraphDocument):
9696
e.add_note(f"No edge type '{r.edge_type}")
9797
else:
9898
relationship = next(
99-
(
100-
candidate
101-
for candidate in relationships
102-
if r.source_type in candidate.source_types
103-
if r.target_type in candidate.target_types
104-
)
99+
candidate
100+
for candidate in relationships
101+
if r.source_type in candidate.source_types
102+
if r.target_type in candidate.target_types
105103
)
106104
if relationship is None:
107105
e.add_note(

libs/knowledge-graph/ragstack_knowledge_graph/traverse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def fetch_relationships(distance: int, source: Node) -> None:
190190
return results
191191

192192

193-
class AsyncPagedQuery(object):
193+
class AsyncPagedQuery:
194194
def __init__(self, depth: int, response_future: ResponseFuture):
195195
self.loop = asyncio.get_running_loop()
196196
self.depth = depth

libs/knowledge-graph/tests/conftest.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ def cassandra_port(db_keyspace: str) -> Iterator[int]:
3535
cassandra.start()
3636
wait_for_logs(cassandra, "Startup complete")
3737
cassandra.get_wrapped_container().exec_run(
38-
(
39-
f"""cqlsh -e "CREATE KEYSPACE {db_keyspace} WITH replication = """
40-
'''{'class': 'SimpleStrategy', 'replication_factor': '1'};"'''
41-
)
38+
f"""cqlsh -e "CREATE KEYSPACE {db_keyspace} WITH replication = """
39+
'''{'class': 'SimpleStrategy', 'replication_factor': '1'};"'''
4240
)
4341
port = cassandra.get_exposed_port(9042)
4442
print(f"Cassandra started. Port is {port}")

libs/knowledge-store/ragstack_knowledge_store/_mmr_helper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def update_redundancy(self, new_weighted_redundancy: float):
3232
self.score = self.weighted_similarity - self.weighted_redundancy
3333

3434

35-
class MmrHelper(object):
35+
class MmrHelper:
3636
dimensions: int
3737
"""Dimensions of the embedding."""
3838

libs/langchain/ragstack_langchain/graph_store/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ async def asearch(
422422
"'mmr' or 'traversal'."
423423
)
424424

425-
def as_retriever(self, **kwargs: Any) -> "GraphStoreRetriever":
425+
def as_retriever(self, **kwargs: Any) -> GraphStoreRetriever:
426426
"""Return GraphStoreRetriever initialized from this GraphStore.
427427
428428
Args:

libs/langchain/ragstack_langchain/graph_store/extractors/link_extractor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from abc import ABC, abstractmethod
4-
from typing import Generic, Iterable, Set, TypeVar
4+
from typing import Generic, Iterable, TypeVar
55

66
from ragstack_langchain.graph_store.links import Link
77

@@ -14,7 +14,7 @@ class LinkExtractor(ABC, Generic[InputT]):
1414
"""Interface for extracting links (incoming, outgoing, bidirectional)."""
1515

1616
@abstractmethod
17-
def extract_one(self, input: InputT) -> Set[Link]:
17+
def extract_one(self, input: InputT) -> set[Link]:
1818
"""Add edges from each `input` to the corresponding documents.
1919
2020
Args:

libs/ragulate/ragstack_ragulate/config/config_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_config(self) -> Config:
2828

2929
@classmethod
3030
def from_file(cls, file_path: str) -> "ConfigParser":
31-
with open(file_path, "r") as file:
31+
with open(file_path) as file:
3232
config = yaml.safe_load(file)
3333

3434
version = config.get("version", 0.1)

libs/tests-utils/ragstack_tests_utils/cassandra_container.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def __init__(
99
port: int = 9042,
1010
**kwargs,
1111
) -> None:
12-
super(CassandraContainer, self).__init__(image=image, **kwargs)
12+
super().__init__(image=image, **kwargs)
1313
self.port = port
1414

1515
self.with_exposed_ports(self.port)

libs/tests-utils/ragstack_tests_utils/test_data.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def _get_test_data_path(file_name: str) -> str:
1313

1414
@staticmethod
1515
def _get_text_file(file_name: str) -> str:
16-
with open(TestData._get_test_data_path(file_name), "r") as f:
16+
with open(TestData._get_test_data_path(file_name)) as f:
1717
return f.read()
1818

1919
@staticmethod
2020
def _get_csv_embedding(csv_file_name: str) -> Embedding:
21-
with open(TestData._get_test_data_path(csv_file_name), "r") as f:
21+
with open(TestData._get_test_data_path(csv_file_name)) as f:
2222
reader = csv.reader(f)
2323
return [[float(value) for value in row] for row in reader]
2424

pyproject.toml

+7
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,16 @@ select = [
6262
"E",
6363
"F",
6464
"I",
65+
"UP",
6566
"W",
6667
]
6768

69+
[tool.ruff.lint.per-file-ignores]
70+
"**/libs/langchain/*" = [
71+
"UP006", # Incompatible with Pydantic v1
72+
"UP007", # Incompatible with Pydantic v1
73+
]
74+
6875
[build-system]
6976
requires = ["poetry-core"]
7077
build-backend = "poetry.core.masonry.api"

scripts/format-example-notebooks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def main():
1616
file = os.path.join(root, file)
1717
if ".ipynb_checkpoints" not in file and file.endswith(".ipynb"):
1818
print("Formatting file: ", file)
19-
with open(file, "r") as f:
19+
with open(file) as f:
2020
contents = f.read()
2121
as_json = json.loads(contents)
2222
cells = as_json["cells"]

scripts/generate-testspace-report.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def parse_snyk_report(input_file: str):
166166
snykfile = os.path.join(input_file, snykfile)
167167
print("Reading file: " + snykfile)
168168

169-
with open(snykfile, "r") as file:
169+
with open(snykfile) as file:
170170
data = json.load(file)
171171
for vulnerability in data.get("vulnerabilities", []):
172172
title = vulnerability.get("title", "?")

scripts/parse-snyk-report.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
input_file = sys.argv[1]
99
output_file = sys.argv[2]
1010

11-
with open(input_file, "r") as file:
11+
with open(input_file) as file:
1212
data = json.load(file)
1313
vulnerabilities = data.get("vulnerabilities", [])
1414

0 commit comments

Comments
 (0)