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 — PEP 695 changed how class decorators are traced · Issue #104686 · python/cpython

PEP 695 changed how class decorators are traced #104686

New issue
Copy link
New issue
Copy link
Closed
Closed
PEP 695 changed how class decorators are traced#104686
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@nedbat
nedbat
opened on May 20, 2023
Issue body actions

Commit 24d8b88 ("gh-103763: Implement PEP 695 (#103764)") changed how nested class decorators are traced.

Example file nightly-20230518.py:

def decorator(arg):
    def _dec(c):
        return c
    return _dec

@decorator(6)
@decorator(
    len([8]),
)
class MyObject(
    object
):
    X = 13
a = 14

Tracing with 3.12.0a7:

% python3.12 -m trace --trace nightly-20230518.py
 --- modulename: nightly-20230518, funcname: <module>
nightly-20230518.py(1): def decorator(arg):
nightly-20230518.py(6): @decorator(6)
 --- modulename: nightly-20230518, funcname: decorator
nightly-20230518.py(2):     def _dec(c):
nightly-20230518.py(4):     return _dec
nightly-20230518.py(7): @decorator(
nightly-20230518.py(8):     len([8]),
nightly-20230518.py(7): @decorator(
 --- modulename: nightly-20230518, funcname: decorator
nightly-20230518.py(2):     def _dec(c):
nightly-20230518.py(4):     return _dec
nightly-20230518.py(10): class MyObject(            <*****
nightly-20230518.py(11):     object
nightly-20230518.py(10): class MyObject(
 --- modulename: nightly-20230518, funcname: MyObject
nightly-20230518.py(6): @decorator(6)
nightly-20230518.py(13):     X = 13
nightly-20230518.py(7): @decorator(
 --- modulename: nightly-20230518, funcname: _dec
nightly-20230518.py(3):         return c
nightly-20230518.py(6): @decorator(6)
 --- modulename: nightly-20230518, funcname: _dec
nightly-20230518.py(3):         return c
nightly-20230518.py(10): class MyObject(
nightly-20230518.py(14): a = 14
% python3.12 -c "import sys; print(sys.version)"
3.12.0a7 (main, Apr  5 2023, 05:51:58) [Clang 14.0.3 (clang-1403.0.22.14.1)]

Running with newer code:

% /usr/local/cpython/bin/python3 -m trace --trace nightly-20230518.py
 --- modulename: nightly-20230518, funcname: <module>
nightly-20230518.py(1): def decorator(arg):
nightly-20230518.py(6): @decorator(6)
 --- modulename: nightly-20230518, funcname: decorator
nightly-20230518.py(2):     def _dec(c):
nightly-20230518.py(4):     return _dec
nightly-20230518.py(7): @decorator(
nightly-20230518.py(8):     len([8]),
nightly-20230518.py(7): @decorator(
 --- modulename: nightly-20230518, funcname: decorator
nightly-20230518.py(2):     def _dec(c):
nightly-20230518.py(4):     return _dec
nightly-20230518.py(6): @decorator(6)               <*****
nightly-20230518.py(11):     object
nightly-20230518.py(10): class MyObject(
 --- modulename: nightly-20230518, funcname: MyObject
nightly-20230518.py(6): @decorator(6)
nightly-20230518.py(13):     X = 13
nightly-20230518.py(7): @decorator(
 --- modulename: nightly-20230518, funcname: _dec
nightly-20230518.py(3):         return c
nightly-20230518.py(6): @decorator(6)
 --- modulename: nightly-20230518, funcname: _dec
nightly-20230518.py(3):         return c
nightly-20230518.py(10): class MyObject(
nightly-20230518.py(14): a = 14
% /usr/local/cpython/bin/python3 -c "import sys; print(sys.version)"
3.12.0a7+ (tags/v3.12.0a7-548-g24d8b88420:24d8b88420, May 20 2023, 06:39:38) [Clang 14.0.3 (clang-1403.0.22.14.1)]

The different lines are marked with <*****.

cc: @JelleZijlstra @markshannon

Linked PRs

  • gh-104686: Fix tracing for decorated classes #104708

Activity

  1. nedbat
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on May 20, 2023
  2. JelleZijlstra commented on May 20, 2023

    @JelleZijlstra
    JelleZijlstra
    on May 20, 2023
    Member
    More actions

    In the disassembly I see that the instructions for creating the class are on a different (wrong) line:

    main:

      8          42 CALL                     1
    
      7          50 PUSH_NULL
                 52 LOAD_BUILD_CLASS
                 54 LOAD_CONST               3 (<code object MyObject at 0x104ea5e40, file "<dis>", line 7>)
                 56 MAKE_FUNCTION            0
                 58 LOAD_CONST               4 ('MyObject')
    
     12          60 LOAD_NAME                2 (object)
    

    3.11:

      8          54 PRECALL                  1
                 58 CALL                     1
    
     11          68 PUSH_NULL
                 70 LOAD_BUILD_CLASS
                 72 LOAD_CONST               3 (<code object MyObject at 0x10536ef50, file "<dis>", line 7>)
                 74 MAKE_FUNCTION            0
                 76 LOAD_CONST               4 ('MyObject')
    
     12          78 LOAD_NAME                2 (object)
    

    So presumably I put the wrong location somewhere in the compiler. I'll take a look.

  3. JelleZijlstra
    added a commit that references this issue on May 20, 2023

    pythongh-104686: Fix tracing for decorated classes

    38559a8
  4. JelleZijlstra commented on May 20, 2023

    @JelleZijlstra
    JelleZijlstra
    on May 20, 2023
    Member
    More actions

    Submitted a fix in #104708, thanks @nedbat for the early report!

  5. JelleZijlstra
    added a commit that references this issue on May 21, 2023

    gh-104686: Fix tracing for decorated classes (#104708)

    cd97484
  6. JelleZijlstra
    closed this as completedon May 21, 2023
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

    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.