-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Property with int return type causes error #318
Comments
Also:
|
Yeah, if you remove the annotation, the method doesn't get instrumented since there would be nothing to check for. |
It's too bad I didn't have a test covering this case. The changes I'm working on now are really the only way forward. The instrumentation needs to copy the annotations into the function body itself. |
The root cause for this is the same as in #315: typeguard's inability to obtain the original function instance to retrieve the correct type hints. I have a fix in the works that bypasses the issue by duplicating the type annotations in the function body. |
Would you mind trying the |
I actually ran into a similar problem with setters. I have a class that defines an args property like:
and then in the class init method I have
typeguard throws a spurious error on |
The above produces a stack trace like that shown below, but it's just a fancy way of saying that the wrapper is trying to invoke the getter function instead of the setter.
|
That was fixed in 835fb65 but not part of a release yet. I discovered two other problem with local variable assignments, where iterable unpacking ( |
That branch works perfectly with my code, it even picked up a small bug! Thank you :) |
Ran into the same problem, e.g.: Traceback (most recent call last):
File "/home/jens/toniecloud/bx_py_utils/bx_py_utils_tests/tests/test_test_utils_redirect.py", line 27, in test_only_stdout
self.assertEqual(buffer.stdout, 'out\n')
File "/home/jens/toniecloud/bx_py_utils/bx_py_utils/test_utils/redirect.py", line 29, in stdout
def stdout(self) -> str:
File "/home/jens/toniecloud/bx_py_utils/.venv/lib/python3.10/site-packages/typeguard/_memo.py", line 70, in __init__
self.type_hints = _type_hints_map[func]
File "/usr/lib/python3.10/weakref.py", line 416, in __getitem__
return self.data[ref(key)]
TypeError: cannot create weak reference to 'property' object The code is here: |
Yes, this was already reported by the original poster, and is already fixed in the |
I tried it now, but it's complete broken, i get this error:
|
blocked until agronholm/typeguard#318 is fixed and released
What's importing |
You're using the wrong branch or revision. CallMemo was entirely removed in a66d170. |
Try removing any |
But if leftover .pyc files are the issue, where is the source code that shows |
Sorry, but I'm not sure I can say. But when I had the OPs issue I tried downgrading to |
At any rate, when upgrading Typeguard, clearing any |
blocked until agronholm/typeguard#318 is fixed and released
FYI: 4.0.0rc1 is out. I will likely update the .pyc suffix to |
Signed-off-by: Tyler Rhodes <tyler.rhodes@equilibriumenergy.com> Update reqs Signed-off-by: Tyler Rhodes <tyler.rhodes@equilibriumenergy.com> Bump to typeguard 4+ to fix agronholm/typeguard#318 fix fix2
Signed-off-by: Tyler Rhodes <tyler.rhodes@equilibriumenergy.com> Update reqs Signed-off-by: Tyler Rhodes <tyler.rhodes@equilibriumenergy.com> Bump to typeguard 4+ to fix agronholm/typeguard#318 fix fix2 Fix error typeguard
Things to check first
I have searched the existing issues and didn't find my bug already reported there
I have checked that my bug is still present in the latest release
Typeguard version
3.0.1
Python version
3.10
What happened?
Thanks for updating Typeguard, though unfortunately, version 3.0.1 causes an error in my code. I've reduced the error down to the example below, which is hopefully self-explanatory!
How can we reproduce the bug?
This code:
Causes the traceback:
I'm expecting this code to run without any error (and print 5).
Please let me know if you'd like any more information, and thank you for maintaining this package!
The text was updated successfully, but these errors were encountered: