Skip to content

Commit 76a4bd7

Browse files
authored
Simplify and correct many numeric unions (#7906)
Unblocks PyCQA/flake8-pyi#222
1 parent 7576805 commit 76a4bd7

File tree

17 files changed

+30
-26
lines changed

17 files changed

+30
-26
lines changed

stdlib/distutils/filelist.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,34 @@ class FileList:
1717
def process_template_line(self, line: str) -> None: ...
1818
@overload
1919
def include_pattern(
20-
self, pattern: str, anchor: int | bool = ..., prefix: str | None = ..., is_regex: Literal[0, False] = ...
20+
self, pattern: str, anchor: bool | Literal[0, 1] = ..., prefix: str | None = ..., is_regex: Literal[0, False] = ...
2121
) -> bool: ...
2222
@overload
2323
def include_pattern(self, pattern: str | Pattern[str], *, is_regex: Literal[True, 1] = ...) -> bool: ...
2424
@overload
2525
def include_pattern(
26-
self, pattern: str | Pattern[str], anchor: int | bool = ..., prefix: str | None = ..., is_regex: int | bool = ...
26+
self, pattern: str | Pattern[str], anchor: bool | Literal[0, 1] = ..., prefix: str | None = ..., is_regex: int = ...
2727
) -> bool: ...
2828
@overload
2929
def exclude_pattern(
30-
self, pattern: str, anchor: int | bool = ..., prefix: str | None = ..., is_regex: Literal[0, False] = ...
30+
self, pattern: str, anchor: bool | Literal[0, 1] = ..., prefix: str | None = ..., is_regex: Literal[0, False] = ...
3131
) -> bool: ...
3232
@overload
3333
def exclude_pattern(self, pattern: str | Pattern[str], *, is_regex: Literal[True, 1] = ...) -> bool: ...
3434
@overload
3535
def exclude_pattern(
36-
self, pattern: str | Pattern[str], anchor: int | bool = ..., prefix: str | None = ..., is_regex: int | bool = ...
36+
self, pattern: str | Pattern[str], anchor: bool | Literal[0, 1] = ..., prefix: str | None = ..., is_regex: int = ...
3737
) -> bool: ...
3838

3939
def findall(dir: str = ...) -> list[str]: ...
4040
def glob_to_re(pattern: str) -> str: ...
4141
@overload
4242
def translate_pattern(
43-
pattern: str, anchor: int | bool = ..., prefix: str | None = ..., is_regex: Literal[False, 0] = ...
43+
pattern: str, anchor: bool | Literal[0, 1] = ..., prefix: str | None = ..., is_regex: Literal[False, 0] = ...
4444
) -> Pattern[str]: ...
4545
@overload
4646
def translate_pattern(pattern: str | Pattern[str], *, is_regex: Literal[True, 1] = ...) -> Pattern[str]: ...
4747
@overload
4848
def translate_pattern(
49-
pattern: str | Pattern[str], anchor: int | bool = ..., prefix: str | None = ..., is_regex: int | bool = ...
49+
pattern: str | Pattern[str], anchor: bool | Literal[0, 1] = ..., prefix: str | None = ..., is_regex: int = ...
5050
) -> Pattern[str]: ...

stdlib/filecmp.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ __all__ = ["clear_cache", "cmp", "dircmp", "cmpfiles", "DEFAULT_IGNORES"]
1313
DEFAULT_IGNORES: list[str]
1414
BUFSIZE: Literal[8192]
1515

16-
def cmp(f1: StrOrBytesPath, f2: StrOrBytesPath, shallow: int | bool = ...) -> bool: ...
16+
def cmp(f1: StrOrBytesPath, f2: StrOrBytesPath, shallow: bool | Literal[0, 1] = ...) -> bool: ...
1717
def cmpfiles(
1818
a: AnyStr | PathLike[AnyStr],
1919
b: AnyStr | PathLike[AnyStr],
2020
common: Iterable[AnyStr | PathLike[AnyStr]],
21-
shallow: int | bool = ...,
21+
shallow: bool | Literal[0, 1] = ...,
2222
) -> tuple[list[AnyStr], list[AnyStr], list[AnyStr]]: ...
2323

2424
class dircmp(Generic[AnyStr]):

stdlib/fractions.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Fraction(Rational):
118118
@overload
119119
def __pow__(self, b: complex) -> complex: ...
120120
@overload
121-
def __rpow__(self, a: int | float | Fraction) -> float: ...
121+
def __rpow__(self, a: float | Fraction) -> float: ...
122122
@overload
123123
def __rpow__(self, a: complex) -> complex: ...
124124
def __pos__(self) -> Fraction: ...

stdlib/ftplib.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class FTP:
7070
def getwelcome(self) -> str: ...
7171
def set_debuglevel(self, level: int) -> None: ...
7272
def debug(self, level: int) -> None: ...
73-
def set_pasv(self, val: bool | int) -> None: ...
73+
def set_pasv(self, val: bool | Literal[0, 1]) -> None: ...
7474
def sanitize(self, s: str) -> str: ...
7575
def putline(self, line: str) -> None: ...
7676
def putcmd(self, line: str) -> None: ...

stdlib/itertools.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ _T4 = TypeVar("_T4")
1818
_T5 = TypeVar("_T5")
1919
_T6 = TypeVar("_T6")
2020

21-
_Step: TypeAlias = int | float | SupportsFloat | SupportsInt | SupportsIndex | SupportsComplex
21+
_Step: TypeAlias = SupportsFloat | SupportsInt | SupportsIndex | SupportsComplex
2222

2323
_Predicate: TypeAlias = Callable[[_T], object]
2424

stdlib/locale.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ if sys.version_info >= (3, 7):
126126
else:
127127
def format_string(f: _str, val: Any, grouping: bool = ...) -> _str: ...
128128

129-
def currency(val: int | float | Decimal, symbol: bool = ..., grouping: bool = ..., international: bool = ...) -> _str: ...
129+
def currency(val: float | Decimal, symbol: bool = ..., grouping: bool = ..., international: bool = ...) -> _str: ...
130130
def delocalize(string: _str) -> _str: ...
131131
def atof(string: _str, func: Callable[[_str], float] = ...) -> float: ...
132132
def atoi(string: _str) -> int: ...

stdlib/random.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Random(_random.Random):
6868
def __init__(self, x: Any = ...) -> None: ...
6969
# Using other `seed` types is deprecated since 3.9 and removed in 3.11
7070
if sys.version_info >= (3, 9):
71-
def seed(self, a: int | float | str | bytes | bytearray | None = ..., version: int = ...) -> None: ... # type: ignore[override]
71+
def seed(self, a: float | str | bytes | bytearray | None = ..., version: int = ...) -> None: ... # type: ignore[override]
7272
else:
7373
def seed(self, a: Any = ..., version: int = ...) -> None: ...
7474

stdlib/turtle.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,11 @@ class _Screen(TurtleScreen):
410410
def __init__(self) -> None: ...
411411
# Note int and float are interpreted differently, hence the Union instead of just float
412412
def setup(
413-
self, width: int | float = ..., height: int | float = ..., startx: int | None = ..., starty: int | None = ...
413+
self,
414+
width: int | float = ..., # noqa: Y041
415+
height: int | float = ..., # noqa: Y041
416+
startx: int | None = ...,
417+
starty: int | None = ...,
414418
) -> None: ...
415419
def title(self, titlestring: str) -> None: ...
416420
def bye(self) -> None: ...

stubs/filelock/filelock/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class _Acquire_ReturnProxy:
1313
) -> None: ...
1414

1515
class BaseFileLock:
16-
def __init__(self, lock_file: str, timeout: float | int | str = ...) -> None: ...
16+
def __init__(self, lock_file: str, timeout: float | str = ...) -> None: ...
1717
@property
1818
def lock_file(self) -> str: ...
1919
@property
2020
def timeout(self) -> float: ...
2121
@timeout.setter
22-
def timeout(self, value: int | str | float) -> None: ... # type: ignore
22+
def timeout(self, value: str | float) -> None: ... # type: ignore
2323
@property
2424
def is_locked(self) -> bool: ...
2525
def acquire(self, timeout: float | None = ..., poll_intervall: float = ...) -> _Acquire_ReturnProxy: ...

stubs/opentracing/opentracing/mocktracer/span.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class MockSpan(Span):
2828
@property
2929
def context(self) -> SpanContext: ...
3030
def set_operation_name(self: Self, operation_name: str) -> Self: ...
31-
def set_tag(self: Self, key: str, value: str | bool | int | float) -> Self: ...
31+
def set_tag(self: Self, key: str, value: str | bool | float) -> Self: ...
3232
def log_kv(self: Self, key_values: dict[str, Any], timestamp: float | None = ...) -> Self: ...
3333
def set_baggage_item(self: Self, key: str, value: str) -> Self: ...
3434

stubs/opentracing/opentracing/span.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Span:
1717
def tracer(self) -> Tracer: ...
1818
def set_operation_name(self: Self, operation_name: str) -> Self: ...
1919
def finish(self, finish_time: float | None = ...) -> None: ...
20-
def set_tag(self: Self, key: str, value: str | bool | int | float) -> Self: ...
20+
def set_tag(self: Self, key: str, value: str | bool | float) -> Self: ...
2121
def log_kv(self: Self, key_values: dict[str, Any], timestamp: float | None = ...) -> Self: ...
2222
def set_baggage_item(self: Self, key: str, value: str) -> Self: ...
2323
def get_baggage_item(self, key: str) -> str | None: ...

stubs/protobuf/google/protobuf/internal/containers.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ from google.protobuf.message import Message
1010

1111
_T = TypeVar("_T")
1212
_K = TypeVar("_K", bound=bool | int | str)
13-
_ScalarV = TypeVar("_ScalarV", bound=bool | int | float | str | bytes)
13+
_ScalarV = TypeVar("_ScalarV", bound=bool | float | str | bytes)
1414
_MessageV = TypeVar("_MessageV", bound=Message)
1515
_M = TypeVar("_M")
1616

stubs/protobuf/google/protobuf/internal/extension_dict.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from google.protobuf.message import Message
88
_ContainerMessageT = TypeVar("_ContainerMessageT", bound=Message)
99
_ExtenderMessageT = TypeVar(
1010
"_ExtenderMessageT",
11-
bound=Message | RepeatedScalarFieldContainer[Any] | RepeatedCompositeFieldContainer[Any] | bool | int | float | str | bytes,
11+
bound=Message | RepeatedScalarFieldContainer[Any] | RepeatedCompositeFieldContainer[Any] | bool | float | str | bytes,
1212
)
1313

1414
class _ExtensionFieldDescriptor(FieldDescriptor, Generic[_ContainerMessageT, _ExtenderMessageT]): ...

stubs/pyaudio/pyaudio.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ paMacCoreStreamInfo: PaMacCoreStreamInfo
6969
# Auxiliary types
7070
_ChannelMap: TypeAlias = Sequence[int]
7171
_PaHostApiInfo: TypeAlias = Mapping[str, str | int]
72-
_PaDeviceInfo: TypeAlias = Mapping[str, str | int | float]
72+
_PaDeviceInfo: TypeAlias = Mapping[str, str | float]
7373
_StreamCallback: TypeAlias = Callable[[bytes | None, int, Mapping[str, float], int], tuple[bytes | None, int]]
7474

7575
def get_format_from_width(width: int, unsigned: bool = ...) -> int: ...

stubs/redis/redis/lock.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ class Lock:
3131
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
3232
) -> bool | None: ...
3333
def acquire(
34-
self, blocking: bool | None = ..., blocking_timeout: None | int | float = ..., token: str | bytes | None = ...
34+
self, blocking: bool | None = ..., blocking_timeout: float | None = ..., token: str | bytes | None = ...
3535
) -> bool: ...
3636
def do_acquire(self, token: str | bytes) -> bool: ...
3737
def locked(self) -> bool: ...
3838
def owned(self) -> bool: ...
3939
def release(self) -> None: ...
4040
def do_release(self, expected_token: str | bytes) -> None: ...
41-
def extend(self, additional_time: int | float, replace_ttl: bool = ...) -> bool: ...
42-
def do_extend(self, additional_time: int | float, replace_ttl: bool) -> bool: ...
41+
def extend(self, additional_time: float, replace_ttl: bool = ...) -> bool: ...
42+
def do_extend(self, additional_time: float, replace_ttl: bool) -> bool: ...
4343
def reacquire(self) -> bool: ...
4444
def do_reacquire(self) -> bool: ...

stubs/typed-ast/typed_ast/ast27.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class Repr(expr):
237237
value: expr
238238

239239
class Num(expr):
240-
n: int | float | complex
240+
n: complex
241241

242242
class Str(expr):
243243
s: str | bytes

stubs/typed-ast/typed_ast/ast3.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class Call(expr):
252252
keywords: list[keyword]
253253

254254
class Num(expr):
255-
n: float | int | complex
255+
n: complex
256256

257257
class Str(expr):
258258
s: str

0 commit comments

Comments
 (0)