Skip to content

Default values for AST Nodes #84162

Closed
Closed

Description

@isidentical
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']

    Activity

    1. isidentical commented on Mar 16, 2020

      @isidentical
      SponsorMemberAuthor
      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()
    2. added
      3.9 (EOL)
      stdlib
      type-feature
      on Mar 16, 2020
    3. transferred this issue fromon Apr 10, 2022
    4. JelleZijlstra commented on May 19, 2024

      @JelleZijlstra
      Member

      This was implemented in #105858.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.9 (EOL)stdlibtype-feature

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions