Skip to content

Commit 0450ea2

Browse files
authored
style: Enable most remaining pyupgrade rules for ruff (#2579)
This enables most of the remaining pyupgrade rules for ruff and includes the fixes made by `poetry run ruff check --fix .`.
1 parent 39462d8 commit 0450ea2

File tree

17 files changed

+154
-180
lines changed

17 files changed

+154
-180
lines changed

pyproject.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,30 @@ select = [
8888
"I", # isort
8989
"N", # pep8-naming
9090
"RUF100", # Unused noqa directive
91+
"UP001", # Remove unused imports
92+
"UP003", # Use {} instead of type(...)
93+
"UP004", # Class inherits from object
94+
"UP005", # is deprecated, use
95+
"UP009", # UTF-8 encoding declaration is unnecessary
9196
"UP010", # Unnecessary __future__ import for target Python version
97+
"UP011", # Unnecessary parentheses to functools.lru_cache
98+
"UP012", # Unnecessary call to encode as UTF-8
99+
"UP017", # Use datetime.UTC alias
100+
"UP018", # Unnecessary {literal_type} call (rewrite as a literal)
101+
"UP019", # typing.Text is deprecated, use str
102+
"UP020", # Use builtin open
103+
"UP021", # universal_newlines is deprecated, use text
104+
"UP022", # Sending stdout and stderr to PIPE is deprecated, use capture_output
105+
"UP023", # cElementTree is deprecated, use ElementTree
106+
"UP024", # Replace aliased errors with OSError
107+
"UP025", # Remove unicode literals from strings
108+
"UP026", # mock is deprecated, use unittest.mock
109+
"UP029", # Unnecessary builtin import
110+
"UP034", # Avoid extraneous parentheses
111+
"UP035", # Import from {target} instead:
112+
"UP036", # Version block is outdated for minimum Python version
92113
"UP037", # Remove quotes from type annotation
114+
"UP039", # Unnecessary parentheses after class definition
93115
"FA", # flake8-future-annotations
94116
]
95117

rdflib/extras/external_graph_libs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ def rdflib_to_networkx_graph(
254254

255255
def rdflib_to_graphtool(
256256
graph: Graph,
257-
v_prop_names: List[str] = [str("term")],
258-
e_prop_names: List[str] = [str("term")],
259-
transform_s=lambda s, p, o: {str("term"): s},
260-
transform_p=lambda s, p, o: {str("term"): p},
261-
transform_o=lambda s, p, o: {str("term"): o},
257+
v_prop_names: List[str] = ["term"],
258+
e_prop_names: List[str] = ["term"],
259+
transform_s=lambda s, p, o: {"term": s},
260+
transform_p=lambda s, p, o: {"term": p},
261+
transform_o=lambda s, p, o: {"term": o},
262262
):
263263
"""Converts the given graph into a graph_tool.Graph().
264264

rdflib/plugins/parsers/nquads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def parse( # type: ignore[override]
9191

9292
def parseline(self, bnode_context: Optional[_BNodeContextType] = None) -> None:
9393
self.eat(r_wspace)
94-
if (not self.line) or self.line.startswith(("#")):
94+
if (not self.line) or self.line.startswith("#"):
9595
return # The line is empty or a comment
9696

9797
subject = self.subject(bnode_context)

rdflib/plugins/sparql/sparql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def __hash__(self) -> int:
149149
return self._hash
150150

151151
def project(self, vars: Container[Variable]) -> FrozenDict:
152-
return FrozenDict((x for x in self.items() if x[0] in vars))
152+
return FrozenDict(x for x in self.items() if x[0] in vars)
153153

154154
def disjointDomain(self, other: t.Mapping[Identifier, Identifier]) -> bool:
155155
return not bool(set(self).intersection(other))

rdflib/plugins/stores/regexmatching.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, expr):
3030
self.compiledExpr = re.compile(expr)
3131

3232
def __reduce__(self):
33-
return (REGEXTerm, (str(""),))
33+
return (REGEXTerm, ("",))
3434

3535

3636
def regexCompareQuad(quad, regexQuad): # noqa: N802, N803

test/test_examples.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def test_example(example_file: Path) -> None:
3232

3333
result = subprocess.run(
3434
[sys.executable, f"{example_file}"],
35-
stdout=subprocess.PIPE,
36-
stderr=subprocess.PIPE,
35+
capture_output=True,
3736
)
3837

3938
logging.debug("result = %s", result)

test/test_extras/test_extras_external_graph_libs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_rdflib_to_graphtool():
8282
assert len(list(gt_util.find_edge(mdg, epterm, q))) == 1
8383

8484
mdg = rdflib_to_graphtool(
85-
g, e_prop_names=[str("name")], transform_p=lambda s, p, o: {str("name"): str(p)}
85+
g, e_prop_names=["name"], transform_p=lambda s, p, o: {"name": str(p)}
8686
)
8787
epterm = mdg.edge_properties["name"]
8888
assert len(list(gt_util.find_edge(mdg, epterm, str(p)))) == 3

test/test_graph/test_canonicalization.py

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -29,53 +29,40 @@ def negative_graph_match_test():
2929
"""Test of FRIR identifiers against tricky RDF graphs with blank nodes."""
3030
testInputs = [ # noqa: N806
3131
[
32-
str(
33-
"""@prefix : <http://example.org/ns#> .
32+
"""@prefix : <http://example.org/ns#> .
3433
<http://example.org> :rel
3534
[ :label "Same" ].
36-
"""
37-
),
38-
str(
39-
"""@prefix : <http://example.org/ns#> .
35+
""",
36+
"""@prefix : <http://example.org/ns#> .
4037
<http://example.org> :rel
4138
[ :label "Same" ],
4239
[ :label "Same" ].
43-
"""
44-
),
40+
""",
4541
False,
4642
],
4743
[
48-
str(
49-
"""@prefix : <http://example.org/ns#> .
44+
"""@prefix : <http://example.org/ns#> .
5045
<http://example.org> :rel
5146
<http://example.org/a>.
52-
"""
53-
),
54-
str(
55-
"""@prefix : <http://example.org/ns#> .
47+
""",
48+
"""@prefix : <http://example.org/ns#> .
5649
<http://example.org> :rel
5750
<http://example.org/a>,
5851
<http://example.org/a>.
59-
"""
60-
),
52+
""",
6153
True,
6254
],
6355
[
64-
str(
65-
"""@prefix : <http://example.org/ns#> .
56+
"""@prefix : <http://example.org/ns#> .
6657
:linear_two_step_symmetry_start :related [ :related [ :related :linear_two_step_symmatry_end]],
67-
[ :related [ :related :linear_two_step_symmatry_end]]."""
68-
),
69-
str(
70-
"""@prefix : <http://example.org/ns#> .
58+
[ :related [ :related :linear_two_step_symmatry_end]].""",
59+
"""@prefix : <http://example.org/ns#> .
7160
:linear_two_step_symmetry_start :related [ :related [ :related :linear_two_step_symmatry_end]],
72-
[ :related [ :related :linear_two_step_symmatry_end]]."""
73-
),
61+
[ :related [ :related :linear_two_step_symmatry_end]].""",
7462
True,
7563
],
7664
[
77-
str(
78-
"""@prefix : <http://example.org/ns#> .
65+
"""@prefix : <http://example.org/ns#> .
7966
_:a :rel [
8067
:rel [
8168
:rel [
@@ -84,10 +71,8 @@ def negative_graph_match_test():
8471
];
8572
];
8673
];
87-
]."""
88-
),
89-
str(
90-
"""@prefix : <http://example.org/ns#> .
74+
].""",
75+
"""@prefix : <http://example.org/ns#> .
9176
_:a :rel [
9277
:rel [
9378
:rel [
@@ -98,14 +83,12 @@ def negative_graph_match_test():
9883
];
9984
];
10085
];
101-
]."""
102-
),
86+
].""",
10387
False,
10488
],
10589
# This test fails because the algorithm purposefully breaks the symmetry of symetric
10690
[
107-
str(
108-
"""@prefix : <http://example.org/ns#> .
91+
"""@prefix : <http://example.org/ns#> .
10992
_:a :rel [
11093
:rel [
11194
:rel [
@@ -114,10 +97,8 @@ def negative_graph_match_test():
11497
];
11598
];
11699
];
117-
]."""
118-
),
119-
str(
120-
"""@prefix : <http://example.org/ns#> .
100+
].""",
101+
"""@prefix : <http://example.org/ns#> .
121102
_:a :rel [
122103
:rel [
123104
:rel [
@@ -126,13 +107,11 @@ def negative_graph_match_test():
126107
];
127108
];
128109
];
129-
]."""
130-
),
110+
].""",
131111
True,
132112
],
133113
[
134-
str(
135-
"""@prefix : <http://example.org/ns#> .
114+
"""@prefix : <http://example.org/ns#> .
136115
_:a :rel [
137116
:rel [
138117
:label "foo";
@@ -142,10 +121,8 @@ def negative_graph_match_test():
142121
];
143122
];
144123
];
145-
]."""
146-
),
147-
str(
148-
"""@prefix : <http://example.org/ns#> .
124+
].""",
125+
"""@prefix : <http://example.org/ns#> .
149126
_:a :rel [
150127
:rel [
151128
:rel [
@@ -154,13 +131,11 @@ def negative_graph_match_test():
154131
];
155132
];
156133
];
157-
]."""
158-
),
134+
].""",
159135
False,
160136
],
161137
[
162-
str(
163-
"""@prefix : <http://example.org/ns#> .
138+
"""@prefix : <http://example.org/ns#> .
164139
_:0001 :rel _:0003, _:0004.
165140
_:0002 :rel _:0005, _:0006.
166141
_:0003 :rel _:0001, _:0007, _:0010.
@@ -171,10 +146,8 @@ def negative_graph_match_test():
171146
_:0008 :rel _:0004, _:0006, _:0010.
172147
_:0009 :rel _:0004, _:0005, _:0007.
173148
_:0010 :rel _:0003, _:0006, _:0008.
174-
"""
175-
),
176-
str(
177-
"""@prefix : <http://example.org/ns#> .
149+
""",
150+
"""@prefix : <http://example.org/ns#> .
178151
_:0001 :rel _:0003, _:0004.
179152
_:0002 :rel _:0005, _:0006.
180153
_:0003 :rel _:0001, _:0007, _:0010.
@@ -185,8 +158,7 @@ def negative_graph_match_test():
185158
_:0005 :rel _:0002, _:0007, _:0009.
186159
_:0006 :rel _:0002, _:0008, _:0010.
187160
_:0007 :rel _:0003, _:0005, _:0009.
188-
"""
189-
),
161+
""",
190162
True,
191163
],
192164
]

test/test_graph/test_graph_http.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def test_3xx(self) -> None:
167167
MockHTTPResponse(
168168
302,
169169
"FOUND",
170-
"".encode(),
170+
b"",
171171
{"Location": [f"{url}/loc/302/{idx}"]},
172172
)
173173
)
@@ -176,7 +176,7 @@ def test_3xx(self) -> None:
176176
MockHTTPResponse(
177177
303,
178178
"See Other",
179-
"".encode(),
179+
b"",
180180
{"Location": [f"{url}/loc/303/{idx}"]},
181181
)
182182
)
@@ -185,7 +185,7 @@ def test_3xx(self) -> None:
185185
MockHTTPResponse(
186186
308,
187187
"Permanent Redirect",
188-
"".encode(),
188+
b"",
189189
{"Location": [f"{url}/loc/308/{idx}"]},
190190
)
191191
)
@@ -229,7 +229,7 @@ def test_5xx(self):
229229
with ServedBaseHTTPServerMock() as httpmock:
230230
url = httpmock.url
231231
httpmock.responses[MethodName.GET].append(
232-
MockHTTPResponse(500, "Internal Server Error", "".encode(), {})
232+
MockHTTPResponse(500, "Internal Server Error", b"", {})
233233
)
234234

235235
graph = Graph()

test/test_issues/test_issue446.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding=utf-8
21
# test for https://github.com/RDFLib/rdflib/issues/446
32

43
from rdflib import Graph, URIRef

0 commit comments

Comments
 (0)