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

Fix some issues with AST node classes #84180

Closed
serhiy-storchaka opened this issue Mar 18, 2020 · 5 comments
Closed

Fix some issues with AST node classes #84180

serhiy-storchaka opened this issue Mar 18, 2020 · 5 comments
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 39999
Nosy @serhiy-storchaka, @isidentical
PRs
  • bpo-39999: Improve compatibility of the ast module. #19056
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-03-22.18:35:56.127>
    created_at = <Date 2020-03-18.09:38:50.352>
    labels = ['type-feature', 'library', '3.9']
    title = 'Fix some issues with AST node classes'
    updated_at = <Date 2020-03-22.18:35:56.127>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2020-03-22.18:35:56.127>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-03-22.18:35:56.127>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2020-03-18.09:38:50.352>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39999
    keywords = ['patch']
    message_count = 5.0
    messages = ['364504', '364507', '364508', '364510', '364814']
    nosy_count = 2.0
    nosy_names = ['serhiy.storchaka', 'BTaskaya']
    pr_nums = ['19056']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue39999'
    versions = ['Python 3.9']

    @serhiy-storchaka
    Copy link
    Member Author

    The proposed PR fixes some issues related to recent changes in the AST node classes.

    1. Re-add removed classes Suite, Param, AugLoad and AugStore. They are not used in Python 3, are not created by the parser and are not accepted by the compiler. Param was used in 2.7, other classes were not used longer time. But some third-party projects (e.g. pyflakes) use them for isinstance checks.

    2. Add docstrings for all dummy AST classes (Constant subclasses, Index, ExtTuple and the above four classes). Otherwise they inherited docstrings from the parent class.

    3. Add docstrings for all attribute aliases.

    4. Set __module__ = "ast" instead of "_ast" for all classes defined in the _ast module. Otherwise the help for the ast module would show only dummy classes, not actual AST node classes. It also makes pickles more compatible between versions.

    @serhiy-storchaka serhiy-storchaka added 3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Mar 18, 2020
    @isidentical
    Copy link
    Sponsor Member

    1. Re-add removed classes Suite, Param, AugLoad and AugStore. They are not used in Python 3, are not created by the parser and are not accepted by the compiler. Param was used in 2.7, other classes were not used longer time. But some third-party projects (e.g. pyflakes) use them for isinstance checks.

    I dont think Suite used in anywhere related to CPython, and for others (Param and AugXXXX contexts, which both used in pyflakes) I dont think it is necessary to have them. For most of the part they can just do this

    if not PY27:
         class Param(ast.expr_context): pass

    and looks like pyflakes already have a PR about this (not this way, but it is common to have version-specific conditions in AST tools).

    @serhiy-storchaka
    Copy link
    Member Author

    Yes, and this what PR 19056 does. It is not difficult, and if we can avoid a breakage, why not do this? We have kept all other deprecated classes, like Num and ExtSlice. In 3.10 we can add runtime warnings, and remove them in some future releases.

    We alreade got a benefit of simplifying the compiler. Maintaining dummy classes does not cost much.

    @isidentical
    Copy link
    Sponsor Member

    I see, thanks for the explanation.

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset bace59d by Serhiy Storchaka in branch 'master':
    bpo-39999: Improve compatibility of the ast module. (GH-19056)
    bace59d

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants