fix: AttributeError
by checking method types in custom metaclasses
#125
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thanks for the great package!
I had a case where I tried to inherit from
EnforceOverrides
when using a custom metaclass, inheriting fromabc.ABCMeta
at the same time. As this was not possible due to Python's requirement that the metaclass of a subclass must be a subclass of the metaclass of all its bases, I ended up importingEnforceOverridesMeta
directly fromoverrides.enforce
and using it as the base of my custom metaclass.Here is an example when using the
EnforceOverridesMeta
on a custom metaclass:Attempting to set the
__ignored__
attribute onfoo
raises anAttributeError
because the method objects, particulary those bound to a class, do not support attribute assignments.I think it would be great if we could export
EnforceOverridesMeta
from the package directly and use it as the base of our own custom metaclasses.This PR exports the
EnforceOverridesMeta
metaclass from the package and implements a check for the type of method objects in the metaclass to differentiate between function objects and other callable types that do not support attribute assignments. By identifying function types bytypes.FunctionType
, this fix avoids theAttributeError
.