https://github.com/python/cpython/commit/d673601d3370d94b33cbed25b4264e774ce95d42
commit: d673601d3370d94b33cbed25b4264e774ce95d42
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: pablogsal <[email protected]>
date: 2026-11-19T12:13:19Z
summary:
[3.15] gh-157227: Remove dead integer-location handling from sampling
collectors (GH-162241) (#162264)
Remove the integer-location branches from the sampling collectors. Live samples
and binary replay use four-field locations or None.
files:
M Lib/profiling/sampling/collector.py
M Lib/profiling/sampling/gecko_collector.py
M Lib/profiling/sampling/live_collector/collector.py
M Lib/profiling/sampling/pstats_collector.py
M Lib/test/test_profiling/test_sampling_profiler/test_binary_format.py
M Lib/test/test_profiling/test_sampling_profiler/test_collectors.py
diff --git a/Lib/profiling/sampling/collector.py
b/Lib/profiling/sampling/collector.py
index 1dc3656e0ebe976..3e2baa0f1a6f91d 100644
--- a/Lib/profiling/sampling/collector.py
+++ b/Lib/profiling/sampling/collector.py
@@ -20,16 +20,13 @@ def normalize_location(location):
"""Normalize location to a 4-tuple format.
Args:
- location: tuple (lineno, end_lineno, col_offset, end_col_offset),
- an integer line number, or None
+ location: tuple (lineno, end_lineno, col_offset, end_col_offset) or
None
Returns:
tuple: (lineno, end_lineno, col_offset, end_col_offset)
"""
if location is None:
return DEFAULT_LOCATION
- if isinstance(location, int):
- return (location, location, -1, -1)
return location
@@ -37,16 +34,13 @@ def extract_lineno(location):
"""Extract lineno from location.
Args:
- location: tuple (lineno, end_lineno, col_offset, end_col_offset),
- an integer line number, or None
+ location: tuple (lineno, end_lineno, col_offset, end_col_offset) or
None
Returns:
int: The line number (0 for synthetic frames)
"""
if location is None:
return 0
- if isinstance(location, int):
- return location
return location[0]
def _is_internal_frame(frame):
diff --git a/Lib/profiling/sampling/gecko_collector.py
b/Lib/profiling/sampling/gecko_collector.py
index 2de8cce387e7f26..90092ac7d86fe72 100644
--- a/Lib/profiling/sampling/gecko_collector.py
+++ b/Lib/profiling/sampling/gecko_collector.py
@@ -368,11 +368,10 @@ def _record_stack_sample(self, thread_data, frames, tid,
times, first_time):
if self.opcodes_enabled and frames:
leaf_frame = frames[0]
filename, location, funcname, opcode = leaf_frame
- if isinstance(location, tuple):
- lineno, _, col_offset, _ = location
+ if location is None:
+ lineno, col_offset = None, -1
else:
- lineno = location
- col_offset = -1
+ lineno, _, col_offset, _ = location
current_state = (opcode, lineno, col_offset, funcname, filename)
@@ -541,15 +540,11 @@ def _process_stack(self, thread_data, frames):
for frame_tuple in reversed(frames):
# frame_tuple is (filename, location, funcname, opcode)
- # location is (lineno, end_lineno, col_offset, end_col_offset) or
just lineno
filename, location, funcname, opcode = frame_tuple
- if isinstance(location, tuple):
- lineno, end_lineno, col_offset, end_col_offset = location
+ if location is None:
+ lineno, col_offset = None, -1
else:
- # Legacy format: location is just lineno
- lineno = location
- col_offset = -1
- end_col_offset = -1
+ lineno, _, col_offset, _ = location
# Get or create function
func_idx = self._get_or_create_func(
diff --git a/Lib/profiling/sampling/live_collector/collector.py
b/Lib/profiling/sampling/live_collector/collector.py
index c5bd0178f2636b6..29f88cfa1eb7749 100644
--- a/Lib/profiling/sampling/live_collector/collector.py
+++ b/Lib/profiling/sampling/live_collector/collector.py
@@ -316,7 +316,6 @@ def process_frames(self, frames, thread_id=None):
self._seen_locations.clear()
# Process each frame in the stack to track cumulative calls
- # frame.location is (lineno, end_lineno, col_offset, end_col_offset),
int, or None
for frame in frames:
lineno = extract_lineno(frame.location)
location = (frame.filename, lineno, frame.funcname)
diff --git a/Lib/profiling/sampling/pstats_collector.py
b/Lib/profiling/sampling/pstats_collector.py
index 0f31d93582b83e7..66144f9fdbf192a 100644
--- a/Lib/profiling/sampling/pstats_collector.py
+++ b/Lib/profiling/sampling/pstats_collector.py
@@ -30,7 +30,6 @@ def _process_frames(self, frames, weight=1):
self._seen_locations.clear()
# Process each frame in the stack to track cumulative calls
- # frame.location is int, tuple (lineno, end_lineno, col_offset,
end_col_offset), or None
for frame in frames:
lineno = extract_lineno(frame.location)
location = (frame.filename, lineno, frame.funcname)
diff --git
a/Lib/test/test_profiling/test_sampling_profiler/test_binary_format.py
b/Lib/test/test_profiling/test_sampling_profiler/test_binary_format.py
index 66a9c68a61c47dc..7b044bf603b9927 100644
--- a/Lib/test/test_profiling/test_sampling_profiler/test_binary_format.py
+++ b/Lib/test/test_profiling/test_sampling_profiler/test_binary_format.py
@@ -63,29 +63,16 @@ def make_interpreter(interp_id, threads):
return InterpreterInfo((interp_id, threads))
-def extract_lineno(location):
- """Extract line number from location (tuple or int or None)."""
- if location is None:
- return 0 # Treat None as 0
- if isinstance(location, tuple):
- return location[0] if location[0] is not None else 0
- return location
-
-
def extract_location(location):
"""Extract full location info as dict from location tuple or None."""
if location is None:
return {"lineno": 0, "end_lineno": 0, "column": 0, "end_column": 0}
- if isinstance(location, tuple) and len(location) >= 4:
- return {
- "lineno": location[0] if location[0] is not None else 0,
- "end_lineno": location[1] if location[1] is not None else 0,
- "column": location[2] if location[2] is not None else 0,
- "end_column": location[3] if location[3] is not None else 0,
- }
- # Fallback for old-style location
- lineno = location[0] if isinstance(location, tuple) else location
- return {"lineno": lineno or 0, "end_lineno": lineno or 0, "column": 0,
"end_column": 0}
+ return {
+ "lineno": location[0],
+ "end_lineno": location[1],
+ "column": location[2],
+ "end_column": location[3],
+ }
def frame_to_dict(frame):
diff --git a/Lib/test/test_profiling/test_sampling_profiler/test_collectors.py
b/Lib/test/test_profiling/test_sampling_profiler/test_collectors.py
index d4ba2df5044559f..dcac6f3e7dfd9e7 100644
--- a/Lib/test/test_profiling/test_sampling_profiler/test_collectors.py
+++ b/Lib/test/test_profiling/test_sampling_profiler/test_collectors.py
@@ -2957,20 +2957,6 @@ def test_extract_lineno_from_none(self):
"""Test extracting lineno from None (synthetic frames)."""
self.assertEqual(extract_lineno(None), 0)
- def test_extract_lineno_from_int(self):
- """Test extracting lineno from a bare integer line number.
-
- Mirrors normalize_location's int contract so callers like the
- collapsed/flamegraph collectors do not crash on a bare-int location.
- """
- self.assertEqual(extract_lineno(42), 42)
- self.assertEqual(extract_lineno(0), 0)
-
- def test_normalize_location_with_int(self):
- """Test normalize_location expands a legacy integer line number."""
- result = normalize_location(42)
- self.assertEqual(result, (42, 42, -1, -1))
-
def test_normalize_location_with_location_info(self):
"""Test normalize_location passes through LocationInfo."""
loc = LocationInfo(10, 15, 0, 5)
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]