Skip to content

Commit f89f0f2

Browse files
committed
fix linting based off ruff's suggestions
1 parent 1021b69 commit f89f0f2

15 files changed

Lines changed: 17 additions & 34 deletions

benchmarks/becnhmark.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,7 @@
9999

100100

101101
def benchmark_name(name, ctx, prefix=None, use_prefix=False):
102-
if use_prefix:
103-
return "%s%s" % (prefix % ctx, name)
104-
105-
return name
102+
return f"{prefix % ctx}{name}" if use_prefix else name
106103

107104

108105
def add_impl_option(cmd, args):

benchmarks/istr.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@
3333

3434

3535
def benchmark_name(name, ctx, prefix=None, use_prefix=False):
36-
if use_prefix:
37-
return "%s%s" % (prefix % ctx, name)
38-
39-
return name
36+
return f"{prefix % ctx}{name}" if use_prefix else name
4037

4138

4239
def add_impl_option(cmd, args):

multidict/_abc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def keys(self) -> Iterable[istr]: ...
2222
def __getitem__(self, key: istr, /) -> _V_co: ...
2323

2424

25-
MDArg = Union[SupportsKeys[_V], SupportsIKeys[_V], Iterable[tuple[str, _V]], None]
25+
MDArg = SupportsKeys[_V] | SupportsIKeys[_V] | Iterable[tuple[str, _V]] | None
2626

2727

2828
class MultiMapping(Mapping[str, _V_co]):

multidict/_multidict_py.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ def getall(self, key: str, default: _T | _SENTINEL = sentinel) -> list[_V] | _T:
667667
return res
668668
if not res and default is not sentinel:
669669
return default
670-
raise KeyError("Key not found: %r" % key)
670+
raise KeyError(f"Key not found: {key!r}")
671671

672672
@overload
673673
def getone(self, key: str) -> _V: ...
@@ -685,7 +685,7 @@ def getone(self, key: str, default: _T | _SENTINEL = sentinel) -> _V | _T:
685685
return e.value
686686
if default is not sentinel:
687687
return default
688-
raise KeyError("Key not found: %r" % key)
688+
raise KeyError(f"Key not found: {key!r}")
689689

690690
# Mapping interface #
691691

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from functools import cached_property
77
from importlib import import_module
88
from types import ModuleType
9-
from typing import Type, Union
109
from collections.abc import Callable
1110

1211
import pytest

tests/gen_pickles.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import pickle
22
from importlib import import_module
33
from pathlib import Path
4-
from typing import Union
54

65
from multidict import CIMultiDict, MultiDict, istr
76

87
TESTS_DIR = Path(__file__).parent.resolve()
9-
_MD_Classes = Union[type[MultiDict[int]], type[CIMultiDict[int]]]
8+
_MD_Classes = type[MultiDict[int]] | type[CIMultiDict[int]]
109

1110

1211
def write(tag: str, cls: _MD_Classes, proto: int) -> None:

tests/test_copy.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import copy
2-
from typing import Union
32

43
from multidict import CIMultiDict, CIMultiDictProxy, MultiDict, MultiDictProxy
54

6-
_MD_Classes = Union[type[MultiDict[int]], type[CIMultiDict[int]]]
7-
_MDP_Classes = Union[type[MultiDictProxy[int]], type[CIMultiDictProxy[int]]]
5+
_MD_Classes = type[MultiDict[int]] | type[CIMultiDict[int]]
6+
_MDP_Classes = type[MultiDictProxy[int]] | type[CIMultiDictProxy[int]]
87

98

109
def test_copy(any_multidict_class: _MD_Classes) -> None:

tests/test_istr.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import gc
22
import sys
3-
from typing import Type
43
from collections.abc import Callable
54

65
import pytest

tests/test_leaks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def test_leak(script: str) -> None:
2828

2929
subprocess.run(
3030
[sys.executable, "-u", "-m", "coverage", "run", str(leak_test_script)],
31-
stdout=subprocess.PIPE,
32-
stderr=subprocess.PIPE,
31+
capture_output=True,
3332
check=True,
3433
)

tests/test_multidict.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,11 @@ def test__repr__(self, cls: type[MultiDict[str]]) -> None:
741741
d = cls()
742742
_cls = type(d)
743743

744-
assert str(d) == "<%s()>" % _cls.__name__
744+
assert str(d) == f"<{_cls.__name__}()>"
745745

746746
d = cls([("key", "one"), ("key", "two")])
747747

748-
assert str(d) == "<%s('key': 'one', 'key': 'two')>" % _cls.__name__
748+
assert str(d) == f"<{_cls.__name__}('key': 'one', 'key': 'two')>"
749749

750750
def test__repr___recursive(
751751
self, any_multidict_class: type[MultiDict[object]]
@@ -756,7 +756,7 @@ def test__repr___recursive(
756756
d = any_multidict_class()
757757
d["key"] = d
758758

759-
assert str(d) == "<%s('key': ...)>" % _cls.__name__
759+
assert str(d) == f"<{_cls.__name__}('key': ...)>"
760760

761761
def test_getall(self, cls: type[MultiDict[str]]) -> None:
762762
d = cls([("key", "value1")], key="value2")
@@ -868,7 +868,7 @@ def test__repr__(self, cls: type[CIMultiDict[str]]) -> None:
868868
d = cls([("KEY", "value1")], key="value2")
869869
_cls = type(d)
870870

871-
expected = "<%s('KEY': 'value1', 'key': 'value2')>" % _cls.__name__
871+
expected = f"<{_cls.__name__}('KEY': 'value1', 'key': 'value2')>"
872872
assert str(d) == expected
873873

874874
def test_items__repr__(self, cls: type[CIMultiDict[str]]) -> None:

0 commit comments

Comments
 (0)