Skip to content

Commit af14926

Browse files
committed
ruff: Enable UP rules
Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent fa730f5 commit af14926

20 files changed

Lines changed: 155 additions & 153 deletions

fixtures/_fixtures/environ.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
]
2020

2121
import os
22-
from typing import Optional
2322

2423
from fixtures import Fixture
2524

@@ -28,9 +27,9 @@ class EnvironmentVariable(Fixture):
2827
"""Isolate a specific environment variable."""
2928

3029
varname: str
31-
newvalue: Optional[str]
30+
newvalue: str | None
3231

33-
def __init__(self, varname: str, newvalue: Optional[str] = None) -> None:
32+
def __init__(self, varname: str, newvalue: str | None = None) -> None:
3433
"""Create an EnvironmentVariable fixture.
3534
3635
:param varname: the name of the variable to isolate.
@@ -40,7 +39,7 @@ def __init__(self, varname: str, newvalue: Optional[str] = None) -> None:
4039
During setup the variable will be deleted or assigned the requested
4140
value, and this will be restored in cleanUp.
4241
"""
43-
super(EnvironmentVariable, self).__init__()
42+
super().__init__()
4443
self.varname = varname
4544
self.newvalue = newvalue
4645

fixtures/_fixtures/logger.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from logging import StreamHandler, getLogger, INFO, Formatter, Handler, LogRecord
1919
import sys
20-
from typing import IO, Optional, Type, TYPE_CHECKING
20+
from typing import IO, TYPE_CHECKING
2121

2222
from fixtures import Fixture
2323
from fixtures._fixtures.streams import StringStream
@@ -42,7 +42,7 @@ def __init__(
4242
self,
4343
handler: Handler,
4444
name: str = "",
45-
level: Optional[int] = None,
45+
level: int | None = None,
4646
nuke_handlers: bool = True,
4747
) -> None:
4848
"""Create a LogHandler fixture.
@@ -54,7 +54,7 @@ def __init__(
5454
:param nuke_handlers: If True remove all existing handles (prevents
5555
existing messages going to e.g. stdout). Defaults to True.
5656
"""
57-
super(LogHandler, self).__init__()
57+
super().__init__()
5858
self.handler = handler
5959
self._name = name
6060
self._level = level
@@ -91,10 +91,10 @@ def __init__(
9191
self,
9292
name: str = "",
9393
level: int = INFO,
94-
format: Optional[str] = None,
95-
datefmt: Optional[str] = None,
94+
format: str | None = None,
95+
datefmt: str | None = None,
9696
nuke_handlers: bool = True,
97-
formatter: Optional[Type[Formatter]] = None,
97+
formatter: type[Formatter] | None = None,
9898
) -> None:
9999
"""Create a FakeLogger fixture.
100100
@@ -116,7 +116,7 @@ def test_log(self)
116116
logging.info('message')
117117
self.assertEqual('message', fixture.output)
118118
"""
119-
super(FakeLogger, self).__init__()
119+
super().__init__()
120120
self._name = name
121121
self._level = level
122122
self._format = format
@@ -125,7 +125,7 @@ def test_log(self)
125125
self._formatter = formatter
126126

127127
def _setUp(self) -> None:
128-
name = "pythonlogging:'%s'" % self._name
128+
name = f"pythonlogging:'{self._name}'"
129129
stream_fixture = self.useFixture(StringStream(name))
130130
output = stream_fixture.stream
131131
self._output: IO[str] = output

fixtures/_fixtures/mockpatch.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
# under the License.
1717

1818
import unittest.mock as mock
19-
from typing import Any, Callable
19+
from typing import Any
20+
from collections.abc import Callable
2021

2122
import fixtures
2223

@@ -35,7 +36,7 @@ class MockPatchObject(_Base):
3536
"""Deal with code around mock."""
3637

3738
def __init__(self, obj: Any, attr: str, new: Any = None, **kwargs: Any) -> None:
38-
super(MockPatchObject, self).__init__()
39+
super().__init__()
3940
if new is None:
4041
new = mock.DEFAULT
4142
self._get_p: Callable[[], Any] = lambda: mock.patch.object(
@@ -47,7 +48,7 @@ class MockPatch(_Base):
4748
"""Deal with code around mock.patch."""
4849

4950
def __init__(self, obj: str, new: Any = None, **kwargs: Any) -> None:
50-
super(MockPatch, self).__init__()
51+
super().__init__()
5152
if new is None:
5253
new = mock.DEFAULT
5354
self._get_p: Callable[[], Any] = lambda: mock.patch(obj, new, **kwargs)
@@ -91,5 +92,5 @@ def __init__(self, obj: Any, **kwargs: Any) -> None:
9192
:param kwargs: names and values of attributes of obj to be mocked.
9293
9394
"""
94-
super(MockPatchMultiple, self).__init__()
95+
super().__init__()
9596
self._get_p: Callable[[], Any] = lambda: mock.patch.multiple(obj, **kwargs)

fixtures/_fixtures/popen.py

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import random
2222
import subprocess
2323
import sys
24-
from typing import Any, Callable, Dict, IO, List, Optional, Tuple, Union, Final
24+
from typing import Any, IO, Final
25+
from collections.abc import Callable
2526

2627
from fixtures import Fixture
2728

@@ -35,23 +36,23 @@ class _Unpassed:
3536
_unpassed: Final = _Unpassed()
3637

3738

38-
class FakeProcess(object):
39+
class FakeProcess:
3940
"""A test double process, roughly meeting subprocess.Popen's contract."""
4041

41-
def __init__(self, args: Dict[str, Any], info: Dict[str, Any]) -> None:
42+
def __init__(self, args: dict[str, Any], info: dict[str, Any]) -> None:
4243
self._args = args
4344
self.stdin: Any = info.get("stdin")
4445
self.stdout: Any = info.get("stdout")
4546
self.stderr: Any = info.get("stderr")
4647
self.pid: int = random.randint(0, 65536)
4748
self._returncode: int = info.get("returncode", 0)
48-
self.returncode: Optional[int] = None
49+
self.returncode: int | None = None
4950

5051
@property
5152
def args(self) -> Any:
5253
return self._args["args"]
5354

54-
def poll(self) -> Optional[int]:
55+
def poll(self) -> int | None:
5556
"""Get the current value of FakeProcess.returncode.
5657
5758
The returncode is None before communicate() and/or wait() are called,
@@ -61,8 +62,8 @@ def poll(self) -> Optional[int]:
6162
return self.returncode
6263

6364
def communicate(
64-
self, input: Optional[Union[bytes, str]] = None, timeout: Optional[float] = None
65-
) -> Tuple[Any, Any]:
65+
self, input: bytes | str | None = None, timeout: float | None = None
66+
) -> tuple[Any, Any]:
6667
self.returncode = self._returncode
6768
if self.stdin and input:
6869
self.stdin.write(input)
@@ -86,8 +87,8 @@ def kill(self) -> None:
8687
pass
8788

8889
def wait(
89-
self, timeout: Optional[float] = None, endtime: Optional[float] = None
90-
) -> Optional[int]:
90+
self, timeout: float | None = None, endtime: float | None = None
91+
) -> int | None:
9192
if self.returncode is None:
9293
self.communicate()
9394
return self.returncode
@@ -103,7 +104,7 @@ class FakePopen(Fixture):
103104
"""
104105

105106
def __init__(
106-
self, get_info: Callable[[Dict[str, Any]], Dict[str, Any]] = lambda _: {}
107+
self, get_info: Callable[[dict[str, Any]], dict[str, Any]] = lambda _: {}
107108
) -> None:
108109
"""Create a PopenFixture
109110
@@ -127,45 +128,45 @@ def get_info(proc_args):
127128
get_info is not supplied or doesn't return a dict with an explicit
128129
'returncode' key).
129130
"""
130-
super(FakePopen, self).__init__()
131+
super().__init__()
131132
self.get_info = get_info
132133

133134
def _setUp(self) -> None:
134135
self.addCleanup(setattr, subprocess, "Popen", subprocess.Popen)
135136
subprocess.Popen = self # type: ignore[assignment,misc]
136-
self.procs: List[FakeProcess] = []
137+
self.procs: list[FakeProcess] = []
137138

138139
# The method has the correct signature so we error appropriately if called
139140
# wrongly.
140141
def __call__(
141142
self,
142-
args: Union[str, List[str]],
143-
bufsize: Union[int, _Unpassed] = _unpassed,
144-
executable: Union[str, None, _Unpassed] = _unpassed,
145-
stdin: Union[None, int, IO[Any], _Unpassed] = _unpassed,
146-
stdout: Union[None, int, IO[Any], _Unpassed] = _unpassed,
147-
stderr: Union[None, int, IO[Any], _Unpassed] = _unpassed,
148-
preexec_fn: Union[Callable[[], None], None, _Unpassed] = _unpassed,
149-
close_fds: Union[bool, _Unpassed] = _unpassed,
150-
shell: Union[bool, _Unpassed] = _unpassed,
151-
cwd: Union[str, None, _Unpassed] = _unpassed,
152-
env: Union[Dict[str, str], None, _Unpassed] = _unpassed,
153-
universal_newlines: Union[bool, _Unpassed] = _unpassed,
154-
startupinfo: Union[Any, _Unpassed] = _unpassed,
155-
creationflags: Union[int, _Unpassed] = _unpassed,
156-
restore_signals: Union[bool, _Unpassed] = _unpassed,
157-
start_new_session: Union[bool, _Unpassed] = _unpassed,
158-
pass_fds: Union[Any, _Unpassed] = _unpassed,
143+
args: str | list[str],
144+
bufsize: int | _Unpassed = _unpassed,
145+
executable: str | None | _Unpassed = _unpassed,
146+
stdin: None | int | IO[Any] | _Unpassed = _unpassed,
147+
stdout: None | int | IO[Any] | _Unpassed = _unpassed,
148+
stderr: None | int | IO[Any] | _Unpassed = _unpassed,
149+
preexec_fn: Callable[[], None] | None | _Unpassed = _unpassed,
150+
close_fds: bool | _Unpassed = _unpassed,
151+
shell: bool | _Unpassed = _unpassed,
152+
cwd: str | None | _Unpassed = _unpassed,
153+
env: dict[str, str] | None | _Unpassed = _unpassed,
154+
universal_newlines: bool | _Unpassed = _unpassed,
155+
startupinfo: Any | _Unpassed = _unpassed,
156+
creationflags: int | _Unpassed = _unpassed,
157+
restore_signals: bool | _Unpassed = _unpassed,
158+
start_new_session: bool | _Unpassed = _unpassed,
159+
pass_fds: Any | _Unpassed = _unpassed,
159160
*,
160-
group: Union[str, int, None, _Unpassed] = _unpassed,
161-
extra_groups: Union[List[Union[str, int]], None, _Unpassed] = _unpassed,
162-
user: Union[str, int, None, _Unpassed] = _unpassed,
163-
umask: Union[int, None, _Unpassed] = _unpassed,
164-
encoding: Union[str, None, _Unpassed] = _unpassed,
165-
errors: Union[str, None, _Unpassed] = _unpassed,
166-
text: Union[bool, None, _Unpassed] = _unpassed,
167-
pipesize: Union[int, _Unpassed] = _unpassed,
168-
process_group: Union[int, None, _Unpassed] = _unpassed,
161+
group: str | int | None | _Unpassed = _unpassed,
162+
extra_groups: list[str | int] | None | _Unpassed = _unpassed,
163+
user: str | int | None | _Unpassed = _unpassed,
164+
umask: int | None | _Unpassed = _unpassed,
165+
encoding: str | None | _Unpassed = _unpassed,
166+
errors: str | None | _Unpassed = _unpassed,
167+
text: bool | None | _Unpassed = _unpassed,
168+
pipesize: int | _Unpassed = _unpassed,
169+
process_group: int | None | _Unpassed = _unpassed,
169170
) -> FakeProcess:
170171
if sys.version_info < (3, 11) and not isinstance(process_group, _Unpassed):
171172
raise TypeError(

fixtures/_fixtures/pythonpackage.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
]
1919

2020
import os.path
21-
from typing import List, Tuple
2221

2322
from fixtures import Fixture
2423
from fixtures._fixtures.tempdir import TempDir
@@ -33,7 +32,7 @@ class PythonPackage(Fixture):
3332
"""
3433

3534
def __init__(
36-
self, packagename: str, modulelist: List[Tuple[str, bytes]], init: bool = True
35+
self, packagename: str, modulelist: list[tuple[str, bytes]], init: bool = True
3736
) -> None:
3837
"""Create a PythonPackage.
3938

fixtures/_fixtures/streams.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
]
2121

2222
import io
23-
from typing import Callable, Generic, IO, Tuple, TypeVar, Union
23+
from typing import Generic, IO, TypeVar
24+
from collections.abc import Callable
2425

2526
from fixtures import Fixture
2627

@@ -39,7 +40,7 @@ class Stream(Generic[T], Fixture):
3940
def __init__(
4041
self,
4142
detail_name: str,
42-
stream_factory: Callable[[], Tuple[T, Union[IO[bytes], IO[str]]]],
43+
stream_factory: Callable[[], tuple[T, IO[bytes] | IO[str]]],
4344
) -> None:
4445
"""Create a ByteStream.
4546
@@ -48,7 +49,7 @@ def __init__(
4849
(write_stream, content_stream).
4950
"""
5051
self._detail_name = detail_name
51-
self._stream_factory: Callable[[], Tuple[T, Union[IO[bytes], IO[str]]]] = (
52+
self._stream_factory: Callable[[], tuple[T, IO[bytes] | IO[str]]] = (
5253
stream_factory
5354
)
5455

@@ -64,7 +65,7 @@ def _setUp(self) -> None:
6465
)
6566

6667

67-
def _byte_stream_factory() -> Tuple[IO[bytes], IO[bytes]]:
68+
def _byte_stream_factory() -> tuple[IO[bytes], IO[bytes]]:
6869
result = io.BytesIO()
6970
return (result, result)
7071

@@ -79,7 +80,7 @@ def ByteStream(detail_name: str) -> Stream[IO[bytes]]:
7980
return Stream(detail_name, _byte_stream_factory)
8081

8182

82-
def _string_stream_factory() -> Tuple[IO[str], IO[bytes]]:
83+
def _string_stream_factory() -> tuple[IO[str], IO[bytes]]:
8384
lower = io.BytesIO()
8485
upper = io.TextIOWrapper(lower, encoding="utf8")
8586
# See http://bugs.python.org/issue7955

fixtures/_fixtures/tempdir.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import os
2222
import shutil
2323
import tempfile
24-
from typing import Optional
2524

2625
import fixtures
2726

@@ -33,9 +32,9 @@ class TempDir(fixtures.Fixture):
3332
"""
3433

3534
path: str
36-
rootdir: Optional[str]
35+
rootdir: str | None
3736

38-
def __init__(self, rootdir: Optional[str] = None) -> None:
37+
def __init__(self, rootdir: str | None = None) -> None:
3938
"""Create a TempDir.
4039
4140
:param rootdir: If supplied force the temporary directory to be a

fixtures/_fixtures/temphomedir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ class TempHomeDir(TempDir):
2828
"""
2929

3030
def _setUp(self) -> None:
31-
super(TempHomeDir, self)._setUp()
31+
super()._setUp()
3232
self.useFixture(EnvironmentVariable("HOME", self.path))

fixtures/_fixtures/timeout.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"""Timeout fixture."""
1818

1919
import signal
20-
from typing import Any, Callable, Optional
20+
from typing import Any
21+
from collections.abc import Callable
2122

2223
import fixtures
2324

@@ -44,7 +45,7 @@ class Timeout(fixtures.Fixture):
4445
"""
4546

4647
timeout_secs: int
47-
alarm_fn: Optional[Callable[[int], int]]
48+
alarm_fn: Callable[[int], int] | None
4849
gentle: bool
4950

5051
def __init__(self, timeout_secs: int, gentle: bool) -> None:

0 commit comments

Comments
 (0)