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

Default values for AST Nodes #84162

Open
isidentical opened this issue Mar 16, 2020 · 1 comment
Open

Default values for AST Nodes #84162

isidentical opened this issue Mar 16, 2020 · 1 comment
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@isidentical
Copy link
Sponsor Member

BPO 39981
Nosy @benjaminp, @serhiy-storchaka, @pablogsal, @isidentical
PRs
  • bpo-39981: Default values for AST nodes #19031
  • bpo-39981: Introduce default values for AST node classes #21417
  • 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 = None
    created_at = <Date 2020-03-16.19:17:20.926>
    labels = ['type-feature', 'library', '3.9']
    title = 'Default values for AST Nodes'
    updated_at = <Date 2020-07-09.13:33:40.873>
    user = 'https://github.com/isidentical'

    bugs.python.org fields:

    activity = <Date 2020-07-09.13:33:40.873>
    actor = 'BTaskaya'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2020-03-16.19:17:20.926>
    creator = 'BTaskaya'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39981
    keywords = ['patch']
    message_count = 1.0
    messages = ['364355']
    nosy_count = 4.0
    nosy_names = ['benjamin.peterson', 'serhiy.storchaka', 'pablogsal', 'BTaskaya']
    pr_nums = ['19031', '21417']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue39981'
    versions = ['Python 3.9']

    @isidentical
    Copy link
    Sponsor Member Author

    For omitting some defaults, @serhiy.storchaka already added support to initialize some ast nodes with some default values (optional fields). An example;
    >>> ast.Constant().kind is None
    True
    
    This isn't exactly a default value, but some kind of class attribute. I think we can push this one step further and initialize all kinds of default values (both optionals and sequences). An example;
    >>> func = ast.FunctionDef("easy_func", ast.arguments(), body=[ast.Pass()])
    >>> func = ast.fix_missing_locations(func)
    >>> exec(compile(ast.Module(body=[func]), "<stdin>", "exec"))
    >>> easy_func()
    
    compared to this (other way around, compiler gives errors so does most of the ast based tool, including ast.unparser)
    >>> func = ast.FunctionDef("easy_func", ast.arguments(posonlyargs=[], args=[], kwonlyargs=[], kw_defaults=[], defaults=[]), decorator_list=[], body=[ast.Pass()])
    >>> func = ast.fix_missing_locations(func)
    >>> exec(compile(ast.Module(body=[func], type_ignores=[]), "<stdin>", "exec"))
    >>> easy_func()

    @isidentical isidentical added 3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Mar 16, 2020
    @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

    1 participant