Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ast types; revert several "redundant numeric union" changes from #7906 #9130

Merged
merged 7 commits into from
Nov 14, 2022
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -26,11 +26,13 @@
# into the typeshed codebase to unblock flake8-pyi PRs, meaning these comments
# have "no matching violations" since the relevant flake8-pyi checks haven't
# yet been released.
# Y041 Use "complex" instead of "float | complex" (see "The numeric tower" in PEP 484)
# Type promotions was changed with mypy 0.990 so all possible types must be listed

[flake8]
per-file-ignores =
*.py: E203, E301, E302, E305, E501
*.pyi: B, E301, E302, E305, E501, E701, E741, NQA102, F401, F403, F405, F822, Y037
*.pyi: B, E301, E302, E305, E501, E701, E741, NQA102, F401, F403, F405, F822, Y037, Y041
# Since typing.pyi defines "overload" this is not recognized by flake8 as typing.overload.
# Unfortunately, flake8 does not allow to "noqa" just a specific error inside the file itself.
# https://github.com/PyCQA/flake8/issues/1079
4 changes: 2 additions & 2 deletions stdlib/_ast.pyi
Original file line number Diff line number Diff line change
@@ -329,7 +329,7 @@ class JoinedStr(expr):

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

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

if sys.version_info >= (3, 8):
class NamedExpr(expr):
2 changes: 1 addition & 1 deletion stdlib/ast.pyi
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ if sys.version_info >= (3, 8):
def __init__(cls, *args: object) -> None: ...

class Num(Constant, metaclass=_ABC):
value: complex
value: int | float | complex

class Str(Constant, metaclass=_ABC):
value: str
4 changes: 1 addition & 3 deletions stdlib/random.pyi
Original file line number Diff line number Diff line change
@@ -41,10 +41,8 @@ class Random(_random.Random):
VERSION: ClassVar[int]
def __init__(self, x: Any = ...) -> None: ...
# Using other `seed` types is deprecated since 3.9 and removed in 3.11
# Ignore Y041, since random.seed doesn't treat int like a float subtype. Having an explicit
# int better documents conventional usage of random.seed.
if sys.version_info >= (3, 9):
def seed(self, a: int | float | str | bytes | bytearray | None = ..., version: int = ...) -> None: ... # type: ignore[override] # noqa: Y041
def seed(self, a: int | float | str | bytes | bytearray | None = ..., version: int = ...) -> None: ... # type: ignore[override]
else:
def seed(self, a: Any = ..., version: int = ...) -> None: ...

6 changes: 1 addition & 5 deletions stdlib/turtle.pyi
Original file line number Diff line number Diff line change
@@ -419,11 +419,7 @@ class _Screen(TurtleScreen):
def __init__(self) -> None: ...
# Note int and float are interpreted differently, hence the Union instead of just float
def setup(
self,
width: int | float = ..., # noqa: Y041
height: int | float = ..., # noqa: Y041
startx: int | None = ...,
starty: int | None = ...,
self, width: int | float = ..., height: int | float = ..., startx: int | None = ..., starty: int | None = ...
) -> None: ...
def title(self, titlestring: str) -> None: ...
def bye(self) -> None: ...
2 changes: 1 addition & 1 deletion stubs/typed-ast/typed_ast/ast27.pyi
Original file line number Diff line number Diff line change
@@ -238,7 +238,7 @@ class Repr(expr):
value: expr

class Num(expr):
n: complex
n: int | float | complex

class Str(expr):
s: str | bytes
2 changes: 1 addition & 1 deletion stubs/typed-ast/typed_ast/ast3.pyi
Original file line number Diff line number Diff line change
@@ -257,7 +257,7 @@ class Call(expr):
keywords: list[keyword]

class Num(expr):
n: complex
n: int | float | complex

class Str(expr):
s: str