Skip to content

Commit 8a041aa

Browse files
Fix UP007
1 parent 0b2278b commit 8a041aa

File tree

8 files changed

+59
-62
lines changed

8 files changed

+59
-62
lines changed

pylint/checkers/classes/class_checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from functools import cached_property
1212
from itertools import chain, zip_longest
1313
from re import Pattern
14-
from typing import TYPE_CHECKING, Any, NamedTuple, Union
14+
from typing import TYPE_CHECKING, Any, NamedTuple, TypeAlias
1515

1616
import astroid
1717
from astroid import bases, nodes, util
@@ -46,7 +46,7 @@
4646
from pylint.lint.pylinter import PyLinter
4747

4848

49-
_AccessNodes = Union[nodes.Attribute, nodes.AssignAttr]
49+
_AccessNodes: TypeAlias = nodes.Attribute | nodes.AssignAttr
5050

5151
INVALID_BASE_CLASSES = {"bool", "range", "slice", "memoryview"}
5252
ALLOWED_PROPERTIES = {"bultins.property", "functools.cached_property"}

pylint/checkers/refactoring/refactoring_checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from collections.abc import Iterator
1212
from functools import cached_property, reduce
1313
from re import Pattern
14-
from typing import TYPE_CHECKING, Any, NamedTuple, Union, cast
14+
from typing import TYPE_CHECKING, Any, NamedTuple, TypeAlias, cast
1515

1616
import astroid
1717
from astroid import bases, nodes
@@ -27,7 +27,7 @@
2727
from pylint.lint import PyLinter
2828

2929

30-
NodesWithNestedBlocks = Union[nodes.Try, nodes.While, nodes.For, nodes.If]
30+
NodesWithNestedBlocks: TypeAlias = nodes.Try | nodes.While | nodes.For | nodes.If
3131

3232
KNOWN_INFINITE_ITERATORS = {"itertools.count", "itertools.cycle"}
3333
BUILTIN_EXIT_FUNCS = frozenset(("quit", "exit"))

pylint/checkers/symilar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from collections.abc import Callable, Generator, Iterable, Sequence
4242
from io import BufferedIOBase, BufferedReader, BytesIO
4343
from itertools import chain
44-
from typing import TYPE_CHECKING, NamedTuple, NewType, NoReturn, TextIO, Union
44+
from typing import TYPE_CHECKING, NamedTuple, NewType, NoReturn, TextIO, TypeAlias
4545

4646
import astroid
4747
from astroid import nodes
@@ -79,7 +79,7 @@ class LineSpecifs(NamedTuple):
7979
IndexToLines_T = dict[Index, "SuccessiveLinesLimits"]
8080

8181
# The types the streams read by pylint can take. Originating from astroid.nodes.Module.stream() and open()
82-
STREAM_TYPES = Union[TextIO, BufferedReader, BytesIO]
82+
STREAM_TYPES: TypeAlias = TextIO | BufferedReader | BytesIO
8383

8484

8585
class CplSuccessiveLinesLimits:

pylint/checkers/typecheck.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from collections.abc import Callable, Iterable
1616
from functools import cached_property, lru_cache, singledispatch
1717
from re import Pattern
18-
from typing import TYPE_CHECKING, Any, Literal, Union
18+
from typing import TYPE_CHECKING, Any, Literal, TypeAlias
1919

2020
import astroid
2121
import astroid.exceptions
@@ -55,13 +55,13 @@
5555
if TYPE_CHECKING:
5656
from pylint.lint import PyLinter
5757

58-
CallableObjects = Union[
59-
bases.BoundMethod,
60-
bases.UnboundMethod,
61-
nodes.FunctionDef,
62-
nodes.Lambda,
63-
nodes.ClassDef,
64-
]
58+
CallableObjects: TypeAlias = (
59+
bases.BoundMethod
60+
| bases.UnboundMethod
61+
| nodes.FunctionDef
62+
| nodes.Lambda
63+
| nodes.ClassDef
64+
)
6565

6666
STR_FORMAT = {"builtins.str.format"}
6767
ASYNCIO_COROUTINE = "asyncio.coroutines.coroutine"

pylint/config/argument.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@
1616
from collections.abc import Callable, Sequence
1717
from glob import glob
1818
from re import Pattern
19-
from typing import Any, Literal, Union
19+
from typing import Any, Literal
2020

2121
from pylint import interfaces
2222
from pylint import utils as pylint_utils
2323
from pylint.config.callback_actions import _CallbackAction
2424
from pylint.config.deprecation_actions import _NewNamesAction, _OldNamesAction
2525

26-
_ArgumentTypes = Union[
27-
str,
28-
int,
29-
float,
30-
bool,
31-
Pattern[str],
32-
Sequence[str],
33-
Sequence[Pattern[str]],
34-
tuple[int, ...],
35-
]
26+
_ArgumentTypes = (
27+
str
28+
| int
29+
| float
30+
| bool
31+
| Pattern[str]
32+
| Sequence[str]
33+
| Sequence[Pattern[str]]
34+
| tuple[int, ...]
35+
)
3636
"""List of possible argument types."""
3737

3838

pylint/extensions/mccabe.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from __future__ import annotations
88

99
from collections.abc import Sequence
10-
from typing import TYPE_CHECKING, Any, TypeVar, Union
10+
from typing import TYPE_CHECKING, Any, TypeAlias, TypeVar
1111

1212
from astroid import nodes
1313
from mccabe import PathGraph as Mccabe_PathGraph
@@ -20,26 +20,26 @@
2020
if TYPE_CHECKING:
2121
from pylint.lint import PyLinter
2222

23-
_StatementNodes = Union[
24-
nodes.Assert,
25-
nodes.Assign,
26-
nodes.AugAssign,
27-
nodes.Delete,
28-
nodes.Raise,
29-
nodes.Yield,
30-
nodes.Import,
31-
nodes.Call,
32-
nodes.Subscript,
33-
nodes.Pass,
34-
nodes.Continue,
35-
nodes.Break,
36-
nodes.Global,
37-
nodes.Return,
38-
nodes.Expr,
39-
nodes.Await,
40-
]
41-
42-
_SubGraphNodes = Union[nodes.If, nodes.Try, nodes.For, nodes.While]
23+
_StatementNodes: TypeAlias = (
24+
nodes.Assert
25+
| nodes.Assign
26+
| nodes.AugAssign
27+
| nodes.Delete
28+
| nodes.Raise
29+
| nodes.Yield
30+
| nodes.Import
31+
| nodes.Call
32+
| nodes.Subscript
33+
| nodes.Pass
34+
| nodes.Continue
35+
| nodes.Break
36+
| nodes.Global
37+
| nodes.Return
38+
| nodes.Expr
39+
| nodes.Await
40+
)
41+
42+
_SubGraphNodes: TypeAlias = nodes.If | nodes.Try | nodes.For | nodes.While
4343
_AppendableNodeT = TypeVar(
4444
"_AppendableNodeT", bound=_StatementNodes | nodes.While | nodes.FunctionDef
4545
)

pylint/typing.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
Any,
1616
Literal,
1717
NamedTuple,
18-
Optional,
1918
Protocol,
2019
TypedDict,
21-
Union,
2220
)
2321

2422
if TYPE_CHECKING:
@@ -107,7 +105,7 @@ class ManagedMessage(NamedTuple):
107105
Options = tuple[tuple[str, OptionDict], ...]
108106

109107

110-
ReportsCallable = Callable[["Section", "LinterStats", Optional["LinterStats"]], None]
108+
ReportsCallable = Callable[["Section", "LinterStats", "LinterStats | None"], None]
111109
"""Callable to create a report."""
112110

113111

@@ -122,10 +120,9 @@ class ExtraMessageOptions(TypedDict, total=False):
122120
default_enabled: bool
123121

124122

125-
MessageDefinitionTuple = Union[
126-
tuple[str, str, str],
127-
tuple[str, str, str, ExtraMessageOptions],
128-
]
123+
MessageDefinitionTuple = (
124+
tuple[str, str, str] | tuple[str, str, str, ExtraMessageOptions]
125+
)
129126
DirectoryNamespaceDict = dict[Path, tuple[argparse.Namespace, "DirectoryNamespaceDict"]]
130127

131128

pylint/utils/utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from collections.abc import Iterable, Sequence
2727
from io import BufferedReader, BytesIO
2828
from re import Pattern
29-
from typing import TYPE_CHECKING, Any, Literal, TextIO, TypeVar, Union
29+
from typing import TYPE_CHECKING, Any, Literal, TextIO, TypeVar
3030

3131
from astroid import Module, modutils, nodes
3232

@@ -54,14 +54,14 @@
5454
]
5555
GLOBAL_OPTION_PATTERN_LIST = Literal["exclude-too-few-public-methods", "ignore-paths"]
5656
GLOBAL_OPTION_TUPLE_INT = Literal["py-version"]
57-
GLOBAL_OPTION_NAMES = Union[
58-
GLOBAL_OPTION_BOOL,
59-
GLOBAL_OPTION_INT,
60-
GLOBAL_OPTION_LIST,
61-
GLOBAL_OPTION_PATTERN,
62-
GLOBAL_OPTION_PATTERN_LIST,
63-
GLOBAL_OPTION_TUPLE_INT,
64-
]
57+
GLOBAL_OPTION_NAMES = (
58+
GLOBAL_OPTION_BOOL
59+
| GLOBAL_OPTION_INT
60+
| GLOBAL_OPTION_LIST
61+
| GLOBAL_OPTION_PATTERN
62+
| GLOBAL_OPTION_PATTERN_LIST
63+
| GLOBAL_OPTION_TUPLE_INT
64+
)
6565
T_GlobalOptionReturnTypes = TypeVar(
6666
"T_GlobalOptionReturnTypes",
6767
bool,

0 commit comments

Comments
 (0)