Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[BUG] Hinting recursion limit will clear the system trace function (sys.gettrace() -> None) #134216

Open
Labels
pendingThe issue will be closed if no feedback is providedtype-bugAn unexpected behavior, bug, or error
@XuehaiPan

Description

@XuehaiPan

Bug report

Bug description:

I'm usingcoverage andpytest-cov in CI to measure the line coverage of the unittests. It is achieved by registering a trace function withsys.settrace.

However, after binsecting my unittests, I found that when aRecursionError is raised, the system trace function will be cleared. That will cause a warning emitted bycoverage:

~/Projects/cpython/venv/lib/python3.15t/site-packages/coverage/pytracer.py:355: CoverageWarning: Trace function changed, data is likely wrong: None != <bound method PyTracer._trace of <PyTracer at 0x200021dcc20: 2076 data points in 11 files>> (trace-changed)  self.warn(

Reproducible code:

importsysdeftracer(*args,**kwargs):passdeffactorial(n:int)->int:"""Calculate the factorial of a number."""ifn<=1:return1returnn*factorial(n-1)sys.settrace(tracer)assertsys.gettrace()istracersys.setrecursionlimit(64)assertsys.gettrace()istracertry:_=factorial(100)exceptRecursionError:passassertsys.gettrace()isNone

REPL Output:

# Add a code block here, if required$python3Python3.13.3 (main,Apr82025,13:54:08) [Clang16.0.0 (clang-1600.0.26.6)]ondarwinType"help","copyright","credits"or"license"formoreinformation.>>>importsys>>>deftracer(*args,**kwargs):...pass...>>>deffactorial(n):...ifn<=1:...return1...returnn*factorial(n-1)...>>>sys.settrace(tracer)>>>sys.gettrace()istracerTrue>>>sys.setrecursionlimit(64)>>> _=factorial(100)Traceback (mostrecentcalllast):File"<python-input-6>",line1,in<module>_=factorial(100)File"<python-input-2>",line4,infactorialreturnn*factorial(n-1)~~~~~~~~^^^^^^^File"<python-input-2>",line4,infactorialreturnn*factorial(n-1)~~~~~~~~^^^^^^^File"<python-input-2>",line4,infactorialreturnn*factorial(n-1)~~~~~~~~^^^^^^^  [Previouslinerepeated51moretimes]File"<python-input-2>",line1,infactorialdeffactorial(n):RecursionError:maximumrecursiondepthexceeded>>>sys.gettrace()isNoneTrue

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp