FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-104686: Fix tracing for decorated classes by JelleZijlstra · Pull Request #104708 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
46 changes: 46 additions & 0 deletions Lib/test/test_sys_settrace.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,52 @@ def __init__(self):
(3, 'return'),
(1, 'return')])

def test_class_creation_with_decorator(self):
def func():
def decorator(arg):
def _dec(c):
return c
return _dec

@decorator(6)
@decorator(
len([8]),
)
class MyObject:
pass

self.run_and_compare(func, [
(0, 'call'),
(1, 'line'),
(6, 'line'),
(1, 'call'),
(2, 'line'),
(4, 'line'),
(4, 'return'),
(7, 'line'),
(8, 'line'),
(7, 'line'),
(1, 'call'),
(2, 'line'),
(4, 'line'),
(4, 'return'),
(10, 'line'),
(6, 'call'),
(6, 'line'),
(11, 'line'),
(11, 'return'),
(7, 'line'),
(2, 'call'),
(3, 'line'),
(3, 'return'),
(6, 'line'),
(2, 'call'),
(3, 'line'),
(3, 'return'),
(10, 'line'),
(10, 'return'),
])

@support.cpython_only
def test_no_line_event_after_creating_generator(self):
# Spurious line events before call events only show up with C tracer
Expand Down
4 changes: 4 additions & 0 deletions Python/compile.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2486,6 +2486,10 @@ compiler_class_body(struct compiler *c, stmt_ty s, int firstlineno)
}

/* 2. load the 'build_class' function */

// these instructions should be attributed to the class line,
// not a decorator line
loc = LOC(s);
ADDOP(c, loc, PUSH_NULL);
ADDOP(c, loc, LOAD_BUILD_CLASS);

Expand Down

Back | FazBrowse Home | New Git URL