Content-Length: 281328 | pFad | https://github.com/python/cpython/issues/99341

1B ast.increment_lineno does not increment line numbers in the Module.type_ignores list · Issue #99341 · python/cpython · GitHub
Skip to content

ast.increment_lineno does not increment line numbers in the Module.type_ignores list #99341

@ricilake

Description

@ricilake

Bug report

As indicated in the title, ast.increment_lineno() does not seem to increment the lineno attributes in the Module's list of TypeIgnore objects, with the result that the type ignore list is disconnected from the location attributes in the rest of the AST.

Example:

>>> import sys
>>> print(sys.version)
3.11.0 (main, Oct 24 2022, 19:56:01) [GCC 7.5.0]
>>> import ast
>>> example="""def t():\n  a = 3 # type: ignore"""
>>> tree = ast.parse(example, type_comments=True)
>>> ast.increment_lineno(tree, 10)
<ast.Module object at 0x7fa7505fbe50>
>>> print(tree.body[0].lineno)
11
>>> print(tree.body[0].body[0].lineno)
12
>>> print(tree.type_ignores[0].lineno)
2

Your environment

Tested using Python 3.11 on an Ubuntu Linux system.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/99341

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy