Skip to content

Update default values for ast.ImportFrom initialization #14308

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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,8 @@ _?ast.excepthandler.__init__
_?ast.expr.__init__
_?ast.stmt.__init__

_ast.ImportFrom.level # None on the class, but never None on instances

argparse.Namespace.__setattr__ # should allow setting any attribute

ast.ImportFrom.level # None on the class, but never None on instances
ast.NodeVisitor.visit_\w+ # Methods are discovered dynamically, see #3796
_?asyncio.Future.__init__ # Usually initialized from c object
asyncio.futures.Future.__init__ # Usually initialized from c object
Expand Down
2 changes: 2 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py39.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ========
# 3.9 only
# ========
_ast.ImportFrom.level # None on the class, but never None on instances
ast.ImportFrom.level # None on the class, but never None on instances

# Exists at runtime, but missing from stubs
collections.AsyncIterable.__class_getitem__
Expand Down
22 changes: 18 additions & 4 deletions stdlib/ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -735,13 +735,27 @@ class ImportFrom(stmt):
__match_args__ = ("module", "names", "level")
module: str | None
names: list[alias]
level: int
if sys.version_info >= (3, 10):
level: int | None
else:
level: int
if sys.version_info >= (3, 13):
@overload
def __init__(self, module: str | None, names: list[alias], level: int, **kwargs: Unpack[_Attributes]) -> None: ...
def __init__(
self, module: None = None, names: list[alias] = ..., *, level: int | None = None, **kwargs: Unpack[_Attributes]
) -> None: ...
@overload
def __init__(
self, module: str | None = None, *, names: list[alias] = ..., level: int | None = None, **kwargs: Unpack[_Attributes]
) -> None: ...
elif sys.version_info >= (3, 10):
@overload
def __init__(
self, module: str | None, names: list[alias], level: int | None = None, **kwargs: Unpack[_Attributes]
) -> None: ...
@overload
def __init__(
self, module: str | None = None, names: list[alias] = ..., *, level: int, **kwargs: Unpack[_Attributes]
self, module: str | None = None, *, names: list[alias], level: int | None = None, **kwargs: Unpack[_Attributes]
) -> None: ...
else:
@overload
Expand All @@ -753,7 +767,7 @@ class ImportFrom(stmt):

if sys.version_info >= (3, 14):
def __replace__(
self, *, module: str | None = ..., names: list[alias] = ..., level: int = ..., **kwargs: Unpack[_Attributes]
self, *, module: str | None = ..., names: list[alias] = ..., level: int | None = ..., **kwargs: Unpack[_Attributes]
) -> Self: ...

class Global(stmt):
Expand Down