8000 Improve `ast` types; revert several "redundant numeric union" changes… · python/typeshed@f9cd5ee · GitHub
[go: up one dir, main page]

Skip to content

Commit f9cd5ee

Browse files
kasiumpre-commit-ci[bot]AlexWaygood
authored
Improve ast types; revert several "redundant numeric union" changes from #7906 (#9130)
* Adapt number types in ast Since mypy 0.990 type promotions was limited. This means that complex is not longer promoted to int/float, therefore we should adapt t 8000 he types to list all possible types Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
1 parent 892bc02 commit f9cd5ee

File tree

7 files changed

+10
-8
lines changed

7 files changed

+10
-8
lines changed

.flake8

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
# into the typeshed codebase to unblock flake8-pyi PRs, meaning these comments
2727
# have "no matching violations" since the relevant flake8-pyi checks haven't
2828
# yet been released.
29+
# Y041 Use "complex" instead of "float | complex" (see "The numeric tower" in PEP 484)
30+
# TODO this check is somewhat broken, see https://github.com/PyCQA/flake8-pyi/issues/299
2931

3032
[flake8]
3133
per-file-ignores =
3234
*.py: E203, E301, E302, E305, E501
33-
*.pyi: B, E301, E302, E305, E501, E701, E741, NQA102, F401, F403, F405, F822, Y037
35+
*.pyi: B, E301, E302, E305, E501, E701, E741, NQA102, F401, F403, F405, F822, Y037, Y041
3436
# Since typing.pyi defines "overload" this is not recognized by flake8 as typing.overload.
3537
# Unfortunately, flake8 does not allow to "noqa" just a specific error inside the file itself.
3638
# https://github.com/PyCQA/flake8/issues/1079

stdlib/_ast.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ class JoinedStr(expr):
329329

330330
if sys.version_info < (3, 8):
331331
class Num(expr): # Deprecated in 3.8; use Constant
332-
n: complex
332+
n: int | float | complex
333333

334334
class Str(expr): # Deprecated in 3.8; use Constant
335335
s: str
@@ -349,7 +349,7 @@ class Constant(expr):
349349
kind: str | None
350350
# Aliases for value, for backwards compatibility
351351
s: Any
352-
n: complex
352+
n: int | float | complex
353353

354354
if sys.version_info >= (3, 8):
355355
class NamedExpr(expr):

stdlib/ast.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if sys.version_info >= (3, 8):
1212
def __init__(cls, *args: object) -> None: ...
1313

1414
class Num(Constant, metaclass=_ABC):
15-
value: complex
15+
value: int | float | complex
1616

1717
class Str(Constant, metaclass=_ABC):
1818
value: str

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 | float | str | bytes)
13+
_ScalarV = TypeVar("_ScalarV", bound=bool | int | float | str | bytes)
1414
_MessageV = TypeVar("_MessageV", bound=Message)
1515
_M = TypeVar("_M")
1616

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 | float]
72+
_PaDeviceInfo: TypeAlias = Mapping[str, str | int | 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/typed-ast/typed_ast/ast27.pyi

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

240240
class Num(expr):
241-
n: complex
241+
n: int | float | complex
242242

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

stubs/typed-ast/typed_ast/ast3.pyi

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

259259
class Num(expr):
260-
n: complex
260+
n: int | float | complex
261261

262262
class Str(expr):
263263
s: str

0 commit comments

Comments
 (0)
0