You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a small utility to exhaustively explore object attributes for comparison of the differences between function objects, decorated function objects, nested decorated function objects, bound and unbound instance methods, bound and unbound class methods, and static methods, to explore runtime and runtime version compatibility and changes to identifying marks.
The test setup is a decorator, various decorated functions, and a class declaration with most possibilities included:
I then have a small amount of (rather deeply nested closure) code to iterate these and identify which are re-discoverable either through direct comparison or through presence of __name__ and self-identification of that name within their REPR output:
foriin (Example, Example.Pandora, Example.Pandora.Box, Example.Pandora.Box.nested, Example.Pandora.nested, Example.instance, Example.classmethod, Example.staticmethod, instance.instance, instance.classmethod, instance.staticmethod, instance):
ifobjisiorobj==i: returnTrue# Can be safely rediscovered through comparison.ifhasattr(i, '__name__') andi.__name__inrepr(obj): returnTrue# Better yet, explicit name.
The above results in:
109: error: "object" has no attribute "__name__"; maybe "__ne__" or "__new__"?
I am somewhat aghast. __name__ isn't universal, but it's extremely common for any scoped object (within a module, class, etc.), and this particular use is guarded in such a way that the attribute access would not happen if missing.
I've pivoted this away from two-component evaluation and towards getattr w/ default, which resolves the complaint. But this should not be a complaint. ;)
The text was updated successfully, but these errors were encountered:
amcgregor
added a commit
to marrow/package
that referenced
this issue
Nov 6, 2019
if you use isinstance(i, type) and i.__name__ ... mypy will probably know what's up -- as far as I know the current narrowing for "instance has attribute" is only through type narrowing (either through isinstance or in rare cases through sys.version_info)
Howdy! Ran into a possible bug or aspect lacking coverage relating to protections against unintentional (/unaware) bad attribute access.
I have a small utility to exhaustively explore object attributes for comparison of the differences between function objects, decorated function objects, nested decorated function objects, bound and unbound instance methods, bound and unbound class methods, and static methods, to explore runtime and runtime version compatibility and changes to identifying marks.
The test setup is a decorator, various decorated functions, and a class declaration with most possibilities included:
I then have a small amount of (rather deeply nested closure) code to iterate these and identify which are re-discoverable either through direct comparison or through presence of
__name__
and self-identification of that name within their REPR output:The above results in:
I am somewhat aghast.
__name__
isn't universal, but it's extremely common for any scoped object (within a module, class, etc.), and this particular use is guarded in such a way that the attribute access would not happen if missing.I've pivoted this away from two-component evaluation and towards
getattr
w/ default, which resolves the complaint. But this should not be a complaint. ;)The text was updated successfully, but these errors were encountered: