Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions line_profiler/_line_profiler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ from libc.stdint cimport int64_t
from libcpp.unordered_map cimport unordered_map
import threading
import opcode
import types

NOP_VALUE: int = opcode.opmap['NOP']

Expand All @@ -32,6 +33,9 @@ NOP_VALUE: int = opcode.opmap['NOP']
# if sys.version_info[0:2] >= (3, 11):
NOP_BYTES: bytes = NOP_VALUE.to_bytes(2, byteorder=byteorder)

# This should be true for Python >=3.11a1
HAS_CO_QUALNAME: bool = hasattr(types.CodeType, 'co_qualname'))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

))

Oops


# long long int is at least 64 bytes assuming c99
ctypedef unsigned long long int uint64
ctypedef long long int int64
Expand Down Expand Up @@ -155,17 +159,20 @@ else:

def label(code):
"""
Return a (filename, first_lineno, qual_name) tuple for a given code object.
Return a (filename, first_lineno, _name) tuple for a given code object.

This is the similar labelling as used by the cProfile module in Python 2.5.

Note:
In Python >=3.11 we use we return qualname for _name.
In older versions of Python we just return name.
"""
if isinstance(code, str):
return ('~', 0, code) # built-in functions ('~' sorts at the end)
else:
try:
# Python >=3.11a1
if HAS_CO_QUALNAME:
return (code.co_filename, code.co_firstlineno, code.co_qualname)
except AttributeError:
else:
return (code.co_filename, code.co_firstlineno, code.co_name)


Expand Down
Loading