wrapt: pydevd error when debugging with wrapt
Hi there,
I tested with python 3.12 & python 3.12.1 (x64) on windows 10 22H2. When I debug with pycharm 2023.3 and wrapt-1.16.0, I get this error:
File "C:\Users\endmarsfr\AppData\Local\Programs\Python\Lib\site-packages\wrapt\decorators.py", line 239, in _build return AdapterWrapper(wrapped=wrapped, wrapper=wrapper, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "_pydevd_bundle/pydevd_pep_669_tracing_cython.pyx", line 504, in _pydevd_bundle.pydevd_pep_669_tracing_cython.PyRaiseCallback.__call__ frame = self.frame File "_pydevd_bundle/pydevd_pep_669_tracing_cython.pyx", line 47, in _pydevd_bundle.pydevd_pep_669_tracing_cython.PEP669CallbackBase.frame while frame and isinstance(frame.f_locals.get('self'), PEP669CallbackBase): ValueError: wrapper has not been initialized python-BaseException
Kind regards
About this issue
- Original URL
- State: open
- Created 7 months ago
- Reactions: 3
- Comments: 27 (10 by maintainers)
@hartym @endmarsfr @GrahamDumpleton Found a workaround on the PyCharm issues tracker. In PyCharm, go to Help > Find Action > Registry and uncheck the box for python.debug.low.impact.monitoring.api.
Debugger did not terminate but am still trying to get the variables to show (this may be from me tinkering with other settings trying to find a solution).Works fine now.Thanks for the confirmation that raising
AttributeError
avoids issue as suspected it might. The trick of using multiple inheritance so the exception type is bothAttributeError
andValueError
is also very interesting. I didn’t even think about such a trick and resolves a concern I had of how to change the error type raised without potentially breaking existing code. I was thinking I would have to release a new version which still usedValueError
, but via an environment variable flag switch it toAttributeError
and allow people to use that to flesh out problems in real world applications before commit to switch toAttributeError
as default.As to monkey patching a temporary fix into existing code, I suspect that wrapt could be used to do that and have it monkey patch itself. I will need to play with that idea as a temporary fix.
@zyoung-rc I confirm your fixture works for me, the small adjustments I made were to use scope=“session” (should the patch be applied once per module ? I believe for now that it can be set for the whole testing session) and autouse=True (so I don’t have to explicitely request it in each test). Also, I did put that code in a conftest.py file at root so pytest just get it. Thanks a lot for your work on that temporary fix !
@GrahamDumpleton I’ve narrowed it down further. It appears PyCharm does not like the
ValueError
raised. Changing it to anAttributeError
seems to appease the debugger. So something likeSomething like this also works and would be more backwards compatible
I hope this helps!
I use pytest and this fixture temporarily fixes the problem until a permanent fix can be made. It can easily be adapted to unittest or another framework.
It’s important to note this patching needs to run before
@wrapt.decorator
is used so you may need to play with the placement.This test will not raise a PyCharm debugging error
This test will
Seems to be the
__class__
property in your example. Here is the example in it’s minimally failing form