GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Annotated assignment in a `match` block does not generate `SETUP_ANNOTATIONS` · Issue #105164 · python/cpython

Annotated assignment in a match block does not generate SETUP_ANNOTATIONS #105164

New issue
Copy link
New issue
Copy link
Closed
Closed
Annotated assignment in a match block does not generate SETUP_ANNOTATIONS#105164
Copy link
Assignees
JelleZijlstra
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)triagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@martindemello
martindemello
opened on May 31, 2023
Issue body actions

Bug report

Compiling the following code:

match 0:
    case 0:
        x: int = 1

generates

  1           0 LOAD_CONST               0 (0)

  2           2 LOAD_CONST               0 (0)
              4 COMPARE_OP               2 (==)
              6 POP_JUMP_IF_FALSE       12 (to 24)

  3           8 LOAD_CONST               1 (1)
             10 STORE_NAME               0 (x)
             12 LOAD_NAME                1 (int)
             14 LOAD_NAME                2 (__annotations__)
             16 LOAD_CONST               2 ('x')
             18 STORE_SUBSCR
             20 LOAD_CONST               3 (None)
             22 RETURN_VALUE

  2     >>   24 LOAD_CONST               3 (None)
             26 RETURN_VALUE

There is no SETUP_ANNOTATIONS opcode generated despite the __annotations__ access later on. (Found via google/pytype#1435 - for some reason this does not generate a runtime error, but it does cause issues for tools like pytype.)

Your environment

cpython 3.10

Linked PRs

  • gh-105164: Detect annotations inside match blocks #105177
  • [3.12] gh-105164: Detect annotations inside match blocks (GH-105177) #105313
  • [3.11] gh-105164: Detect annotations inside match blocks (GH-105177). #105314
Reacted by Gregory P. Smith

Activity

  1. martindemello
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on May 31, 2023
  2. JelleZijlstra
    self-assigned this
    on May 31, 2023
  3. yilei commented on May 31, 2023

    @yilei
    yilei
    on May 31, 2023
    Contributor
    More actions

    FWIW, it's a runtime error when the module is imported, not run as main:

    $ cat lib.py
    match 0:
        case 0:
            x: int = 1
    
    $ cat main.py
    import lib
    
    $ python main.py
    Traceback (most recent call last):
      File "main.py", line 1, in <module>
        import lib
      File "lib.py", line 3, in <module>
        x: int = 1
    NameError: name '__annotations__' is not defined
  4. brandtbucher commented on May 31, 2023

    @brandtbucher
    brandtbucher
    on May 31, 2023
    Member
    More actions

    I think find_ann in compile.c needs to be taught about Match_kind.

    Looks like @JelleZijlstra picked this up already. Feel free to ping me for review!

    Reacted by Jelle Zijlstra and sunmy2019
  5. brandtbucher
    added
    3.11only security fixesonly security fixes
    3.12only security fixesonly security fixes
    3.13only security fixesonly security fixes
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    triagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.
    on May 31, 2023
  6. brandtbucher
    changed the title [-]annotated assignment in a match block does not generate SETUP_ANNOTATIONS[/-] [+]Annotated assignment in a `match` block does not generate `SETUP_ANNOTATIONS`[/+] on May 31, 2023
  7. JelleZijlstra
    added 2 commits that reference this issue on Jun 1, 2023

    pythongh-105164: Detect annotations inside match blocks

    f7ed5ce

    gh-105164: Detect annotations inside match blocks (#105177)

    69d1245
  8. miss-islington
    added a commit that references this issue on Jun 5, 2023

    pythongh-105164: Detect annotations inside match blocks (pythonGH-105177

    2aaae40
  9. JelleZijlstra
    added 3 commits that reference this issue on Jun 5, 2023

    [3.11] pythongh-105164: Detect annotations inside match blocks (pytho…

    9c30ecb

    [3.12] gh-105164: Detect annotations inside match blocks (GH-105177) (#…

    6d03541

    [3.11] gh-105164: Detect annotations inside match blocks (GH-105177). (…

    4895788
  10. hauntsaninja commented on Sep 7, 2023

    @hauntsaninja
    hauntsaninja
    on Sep 7, 2023
    Contributor
    More actions

    Thanks, looks like this is fixed

  11. hauntsaninja
    closed this as completedon Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @JelleZijlstra
    JelleZijlstra

Labels

3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)triagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.