-
Notifications
You must be signed in to change notification settings - Fork 114
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
AttributeError: 'xxxx' object has no attribute '__code__' #191
Comments
I think the issue is that the Is it an issue with the pytest plugin? with the import hook? Note: I use the pytest plugin with |
@agronholm I can confirm that #190 fixes this. Here's a failing test to demonstrate the issue: # tests/test_typeguard.py
class TestTypeChecker:
...
def test_callable(self):
class command:
# we need an __annotations__ attribute to trigger the code path
whatever: float
def __init__(self, function: Callable[[int], int]):
self.function = function
def __call__(self, arg: int) -> None:
self.function(arg)
@typechecked
@command
def function(arg: int) -> None:
pass
function(1) @epenet Feel free to include this in your PR. Some additional info:
|
Here's a temporary workaround for the issue: try:
import typeguard # type: ignore[import]
except ImportError:
pass
else: # pragma: no cover
from typing import no_type_check
@no_type_check
def _patched_typechecked(*args, **kwargs):
if args and isinstance(args[0], click.Command):
return args[0]
return typeguard_typechecked(*args, **kwargs)
typeguard_typechecked = typeguard.typechecked
typeguard.typechecked = _patched_typechecked Not exactly beautiful... I literally found no better way to do this 😞 |
Thanks @cjolowicz I've updated the PR |
Describe the bug
When using https://github.com/pallets/click, the
@click.group()
function decorator return a class instance (click.core.<Group xyz>
) which does not have associated code. This causes Typeguard to fail withAttributeError: 'Group' object has no attribute '__code__'
.To Reproduce
Failure can be seen on https://github.com/hacf-fr/renault-api/runs/2664117342.
I'm working on a smaller reproducible example
Expected behavior
Should pass
Additional context
pallets/click#1927
The text was updated successfully, but these errors were encountered: