Skip to content

ast.MatchStar.name default value is not in "ast.pyi" #14297

@hunterhogan

Description

@hunterhogan

"ast.pyi" reads ast.MatchStar name parameter does not have a default value

Compare and contrast with ast.MatchAs.name.

typeshed/stdlib/ast.pyi

Lines 1590 to 1609 in ecd5141

class MatchStar(pattern):
__match_args__ = ("name",)
name: str | None
def __init__(self, name: str | None, **kwargs: Unpack[_Attributes[int]]) -> None: ...
if sys.version_info >= (3, 14):
def __replace__(self, *, name: str | None = ..., **kwargs: Unpack[_Attributes[int]]) -> Self: ...
class MatchAs(pattern):
__match_args__ = ("pattern", "name")
pattern: _Pattern | None
name: str | None
def __init__(
self, pattern: _Pattern | None = None, name: str | None = None, **kwargs: Unpack[_Attributes[int]]
) -> None: ...
if sys.version_info >= (3, 14):
def __replace__(
self, *, pattern: _Pattern | None = ..., name: str | None = ..., **kwargs: Unpack[_Attributes[int]]
) -> Self: ...

Type checker diagnostics

Mypy and Pylance:

Image

Contrast with ast.MatchAs:

Image

REPL

3.13.5

(.venv) C:\apps\astToolFactory>py
Python 3.13.5 (tags/v3.13.5:6cb20a2, Jun 11 2025, 16:15:46) [MSC v.1943 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> ImaMatchStar = ast.MatchStar()
>>> print(ImaMatchStar.name)
None
>>> print(ImaMatchStar.Beelzebub)
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    print(ImaMatchStar.Beelzebub)
          ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'MatchStar' object has no attribute 'Beelzebub'
>>> 

3.15

(.venv) C:\clones\cpython>pcbuild\amd64\python_d
Python 3.15.0a0 (heads/main:28c71ee4b2e, Jun 17 2025, 22:00:57) [MSC v.1944 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> ast.MatchStar()
MatchStar(name=None)
>>> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions