Skip to content
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

Fix AttributeError when __code__ is missing from the checked callable #190

Merged
merged 7 commits into from
Jun 2, 2021

Conversation

epenet
Copy link
Contributor

@epenet epenet commented May 26, 2021

Fixes: #191

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 with AttributeError: 'Group' object has no attribute '__code__'.

@epenet epenet changed the title Ensure function has code Typecheck on objects May 26, 2021
@epenet epenet changed the title Typecheck on objects Typecheck on class instances May 26, 2021
@agronholm
Copy link
Owner

The test suite fails on Python 3.5 because of the variable annotation. It is on my to-do list to drop 3.5 support in this project but until then, move the test to test_typeguard_py36.py.

@epenet
Copy link
Contributor Author

epenet commented Jun 2, 2021

@agronholm I have moved the tests

@epenet epenet changed the title Typecheck on class instances Ensure __code__ is available on function type checking Jun 2, 2021
@coveralls
Copy link

coveralls commented Jun 2, 2021

Coverage Status

Coverage remained the same at 85.857% when pulling fc69bc5 on epenet:fix-nocode into abcaa5d on agronholm:master.

Copy link
Owner

@agronholm agronholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@epenet epenet changed the title Ensure __code__ is available on function type checking Fixed AttributeError when __code__ is missing from the checked callable Jun 2, 2021
@epenet epenet changed the title Fixed AttributeError when __code__ is missing from the checked callable Fixed AttributeError when __code__ is missing from the checked callable Jun 2, 2021
@epenet epenet changed the title Fixed AttributeError when __code__ is missing from the checked callable Fix AttributeError when __code__ is missing from the checked callable Jun 2, 2021
@agronholm agronholm merged commit 3f12d1f into agronholm:master Jun 2, 2021
@agronholm
Copy link
Owner

Thanks!

@epenet
Copy link
Contributor Author

epenet commented Jun 2, 2021

Thank you for merging this @agronholm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AttributeError: 'xxxx' object has no attribute '__code__'
3 participants