Conversation

koyuki7w

The ast document states that Try/TryStar have an attribute of type excepthandler, not ExceptHandler. Also Module has of type type_ignore, not TypeIgnore.

@github-actionsGitHub Actions

This comment has been minimized.

@brianschubert

Hmm, this doesn't look right. Where in the docs does it indicate this? Are you maybe going by the grammar at the top of the docs, and missed the definitions of type_ignore/execpthandler further down? E.g. type_ignore in the grammar stands for a TypeIgnore node:

    type_ignore = TypeIgnore(int lineno, string tag)

Looking at the nodes at runtime suggests that the current stubs are correct:

>>> ast.parse("# type: ignore", type_comments=True).type_ignores
[<ast.TypeIgnore object at 0x7000551b31d0>]

>>> ast.parse("""
... try:
...     pass
... except:
...     pass
... """).body[0].handlers
[<ast.ExceptHandler object at 0x7000551c8990>]

@github-actionsGitHub Actions

Diff from mypy_primer, showing the effect of this PR on open source code:

mypy (https://.com/python/mypy)
+ mypy/fastparse.py:888: error: "type_ignore" has no attribute "tag"  [attr-defined]
+ mypy/fastparse.py:890: error: "type_ignore" has no attribute "lineno"  [attr-defined]
+ mypy/fastparse.py:892: error: "type_ignore" has no attribute "lineno"  [attr-defined]
+ mypy/fastparse.py:1378: error: "excepthandler" has no attribute "name"  [attr-defined]
+ mypy/fastparse.py:1378: error: Argument 2 to "set_line" of "ASTConverter" has incompatible type "excepthandler"; expected "Union[expr, stmt, ExceptHandler]"  [arg-type]
+ mypy/fastparse.py:1380: error: "excepthandler" has no attribute "type"  [attr-defined]
+ mypy/fastparse.py:1381: error: "excepthandler" has no attribute "body"  [attr-defined]

@koyuki7w

@brianschubert Thanks for the reply. It seems I misread the documentation. I'll close it.

@koyuki7wkoyuki7w deleted the -1 branch June 10, 2025 02:40
Sign up for free to join this conversation on . Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.