Skip to content

Commit 578e0cc

Browse files
committed
Split up regex
1 parent f09e84e commit 578e0cc

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Lib/profiling/sampling/cli.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,19 @@ def _run_with_sync(original_cmd, suppress_output=False):
288288
return process
289289

290290

291-
_RATE_PATTERN = re.compile(r'^(\d+(?:\.\d+)?)(hz|khz|k)?$', re.IGNORECASE)
291+
_RATE_PATTERN = re.compile(r'''
292+
^ # Start of string
293+
( # Group 1: The numeric value
294+
\d+ # One or more digits (integer part)
295+
(?:\.\d+)? # Optional: decimal point followed by digits
296+
) # Examples: "10", "0.5", "100.25"
297+
( # Group 2: Optional unit suffix
298+
hz # "hz" - hertz
299+
| khz # "khz" - kilohertz
300+
| k # "k" - shorthand for kilohertz
301+
)? # Suffix is optional (bare number = Hz)
302+
$ # End of string
303+
''', re.VERBOSE | re.IGNORECASE)
292304

293305

294306
def _parse_sampling_rate(rate_str: str) -> int:

0 commit comments

Comments
 (0)