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

_ast.ast_type_init does not handle args and kwargs correctly. #80471

Closed
remilapeyre mannequin opened this issue Mar 14, 2019 · 4 comments
Closed

_ast.ast_type_init does not handle args and kwargs correctly. #80471

remilapeyre mannequin opened this issue Mar 14, 2019 · 4 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@remilapeyre
Copy link
Mannequin

remilapeyre mannequin commented Mar 14, 2019

BPO 36290
Nosy @brettcannon, @benjaminp, @serhiy-storchaka, @1st1, @pablogsal, @miss-islington, @remilapeyre
PRs
  • bpo-36290: Fix kwargs handling in ast node constructors #12382
  • [3.9] bpo-36290: Fix keyword collision handling in AST node constructors (GH-12382) #20365
  • [3.8] bpo-36290: Fix keyword collision handling in AST node constructors (GH-12382) #20366
  • 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-05-24.21:16:59.156>
    created_at = <Date 2019-03-14.14:47:19.088>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = '_ast.ast_type_init does not handle args and kwargs correctly.'
    updated_at = <Date 2020-05-24.21:32:35.998>
    user = 'https://github.com/remilapeyre'

    bugs.python.org fields:

    activity = <Date 2020-05-24.21:32:35.998>
    actor = 'miss-islington'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-05-24.21:16:59.156>
    closer = 'pablogsal'
    components = ['Library (Lib)']
    creation = <Date 2019-03-14.14:47:19.088>
    creator = 'remi.lapeyre'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36290
    keywords = ['patch']
    message_count = 4.0
    messages = ['337926', '369829', '369831', '369832']
    nosy_count = 7.0
    nosy_names = ['brett.cannon', 'benjamin.peterson', 'serhiy.storchaka', 'yselivanov', 'pablogsal', 'miss-islington', 'remi.lapeyre']
    pr_nums = ['12382', '20365', '20366']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue36290'
    versions = ['Python 3.7', 'Python 3.8']

    @remilapeyre
    Copy link
    Mannequin Author

    remilapeyre mannequin commented Mar 14, 2019

    While looking at bpo-36287 I noticed that the argument parsing logic in _ast.ast_type_init is wrong, for example ast.Constant takes only one argument:

    ✗ ./python.exe 
    Python 3.8.0a2+ (remotes/origin/HEAD-1-ged9b774cf3:ed9b774cf3, Mar 14 2019, 00:50:47) 
    [Clang 10.0.0 (clang-1000.10.44.4)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import ast
    >>> ast.Constant(1, 2)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: Constant constructor takes at most 1 positional argument
    >>> ast.Constant(1)
    <_ast.Constant object at 0x105b52950>
    >>> ast.Constant(value=2)
    <_ast.Constant object at 0x105b528f0>
    >>> ast.Constant(1, value=2)
    <_ast.Constant object at 0x105b529b0>
    >>> ast.Constant(1, value=2).value
    2

    The last lines should have raised TypeError. I could reproduce the issue with Python 2.7, 3.7 and 3.8 but I'm not sure it's worth fixing for 2.7.

    I will write a patch to fix the issue.

    @remilapeyre remilapeyre mannequin added 3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 14, 2019
    @pablogsal
    Copy link
    Member

    New changeset c73914a by Rémi Lapeyre in branch 'master':
    bpo-36290: Fix keytword collision handling in AST node constructors (GH-12382)
    c73914a

    @miss-islington
    Copy link
    Contributor

    New changeset 907ee1f by Miss Islington (bot) in branch '3.8':
    bpo-36290: Fix keytword collision handling in AST node constructors (GH-12382)
    907ee1f

    @miss-islington
    Copy link
    Contributor

    New changeset 1a4e9e6 by Miss Islington (bot) in branch '3.9':
    bpo-36290: Fix keytword collision handling in AST node constructors (GH-12382)
    1a4e9e6

    @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.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants