Skip to content

Add kind field to ast.Constant, to distinguish u"..." from "..." for type checkers #80461

Closed

Description

@gvanrossum
BPO 36280
Nosy @gvanrossum, @serhiy-storchaka, @miss-islington
PRs
  • bpo-36280: Add Constant.kind field #12295
  • 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 = 'https://github.com/gvanrossum'
    closed_at = <Date 2019-03-13.20:01:54.579>
    created_at = <Date 2019-03-13.04:00:08.733>
    labels = ['type-bug', '3.8']
    title = 'Add kind field to ast.Constant, to distinguish u"..." from "..." for type checkers'
    updated_at = <Date 2019-03-13.20:01:54.578>
    user = 'https://github.com/gvanrossum'

    bugs.python.org fields:

    activity = <Date 2019-03-13.20:01:54.578>
    actor = 'gvanrossum'
    assignee = 'gvanrossum'
    closed = True
    closed_date = <Date 2019-03-13.20:01:54.579>
    closer = 'gvanrossum'
    components = []
    creation = <Date 2019-03-13.04:00:08.733>
    creator = 'gvanrossum'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36280
    keywords = ['patch']
    message_count = 5.0
    messages = ['337834', '337853', '337854', '337872', '337873']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'serhiy.storchaka', 'miss-islington']
    pr_nums = ['12295']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue36280'
    versions = ['Python 3.8']

    Activity

    1. self-assigned this
      on Mar 13, 2019
    2. serhiy-storchaka commented on Mar 13, 2019

      @serhiy-storchaka
      Member

      Maybe use a special subclass of Constant for indicating string literals with the "u" prefix?

    3. gvanrossum commented on Mar 13, 2019

      @gvanrossum
      MemberAuthor

      Maybe use a special subclass of Constant for indicating string literals with the "u" prefix?

      That would indeed be more convenient, as it requires fewer code and test changes. Are there examples of such classes in Python.asdl?

    4. gvanrossum commented on Mar 13, 2019

      @gvanrossum
      MemberAuthor

      On second thought, even though it's a subclass, it feels less consistent than an extra attribute. So I'd rather keep the current approach (kind -> 'u' or None).

    5. miss-islington commented on Mar 13, 2019

      @miss-islington
      Contributor

      New changeset 10f8ce6 by Miss Islington (bot) (Guido van Rossum) in branch 'master':
      bpo-36280: Add Constant.kind field (GH-12295)
      10f8ce6

    6. gvanrossum commented on Mar 13, 2019

      @gvanrossum
      MemberAuthor

      Thanks for the review Serhiy!

    7. transferred this issue fromon Apr 10, 2022
    8. vasily-v-ryabov commented on Nov 1, 2023

      @vasily-v-ryabov

      Please correct me if I'm wrong. This Constant.kind field is not used in mypy any more. Previously it was used in fastparse.py (intro by this commit: python/mypy@69a5a02), but now I don't see it in mypy/fastparse.py or anywhere else. Yes, this field is present in ast module interface, and I didn't try to search if it is used by some PyPI package. Maybe you know where it is used. Thanks!

    9. gvanrossum commented on Nov 1, 2023

      @gvanrossum
      MemberAuthor

      @vasily-v-ryabov What is your question, or what action are you requesting we take?

    10. vasily-v-ryabov commented on Nov 2, 2023

      @vasily-v-ryabov

      @gvanrossum Initially I wanted to remove this field as it looked outdated. I've even prepared draft commit vasily-v-ryabov@68906e0 but then I've found this thread and related commits, and also I understood it may potentially break backward compatibility. If there is no such risk, I'd suggest to create a PR or prepare some deprecation. Though this particular commit is not critical to me if this stuff is really used.

      The reason to me is making AST more compact which should be generally good for performance. I'm interested in improvements for AST and compiler related stuff in CPython for my project (hope it will be open in the future).

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

    Metadata

    Metadata

    Assignees

    Labels

    3.8 (EOL)end of lifetype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions