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

isinstance() fails with versionadded and versionchanged #48

Closed
jdogburck opened this issue Aug 25, 2021 · 2 comments
Closed

isinstance() fails with versionadded and versionchanged #48

jdogburck opened this issue Aug 25, 2021 · 2 comments
Assignees
Milestone

Comments

@jdogburck
Copy link

jdogburck commented Aug 25, 2021

Expected Behavior

Using isinstance() for classes annotated with the deprecated library should work as expected, regardless of the number of annotations.

from deprecated.sphinx import versionadded
from deprecated.sphinx import versionchanged
from deprecated.sphinx import deprecated

@versionadded(version='X.Y', reason='some reason')
class VersionAdded:
    pass

@versionadded(version='X.Y', reason='some reason')
class VersionAddedChild(VersionAdded):
    pass

@versionchanged(version='X.Y', reason='some reason')
class VersionChanged:
    pass

@versionchanged(version='X.Y', reason='some reason')
class VersionChangedChild(VersionChanged):
    pass

@deprecated(version='X.Y', reason='some reason')
class Deprecated_:
    pass

@deprecated(version='Y.Z', reason='some reason')
class DeprecatedChild_(Deprecated_):
    pass

@versionadded(version='X.Y')
@versionchanged(version='X.Y.Z')
class AddedChanged:
    pass

# should all be True
print([isinstance(VersionAddedChild(), VersionAddedChild), isinstance(VersionAddedChild(), VersionAdded)])
print([isinstance(VersionChangedChild(), VersionChangedChild), isinstance(VersionChangedChild(), VersionChanged)])
print([isinstance(DeprecatedChild_(), DeprecatedChild_), isinstance(DeprecatedChild_(), Deprecated_)])
print([isinstance(AddedChanged(), AddedChanged)])

Actual Behavior

Tell us what happens instead.

[False, False]
[False, False]
[True, True]   # seems to have been addressed on  0e944e0
[False]

Environment

  • Python version: 3.7.7
  • Deprecated version: 1.2.12
@tantale tantale self-assigned this Aug 25, 2021
@tantale tantale added this to the 1.2.13 milestone Aug 25, 2021
@tantale
Copy link
Collaborator

tantale commented Aug 25, 2021

Typically, for the versionadded and versionchanged directives, the decorator returns the class unchanged (except, of course, the docstring). So it must be transparent to the insinstance function.

As for the deprecated decorator, the call to __new__ is additionally modified to issue a warning. But, again, isinstance should work. Weird…

Have you done your own diagnosis of the problem, which might help?

@jdogburck
Copy link
Author

i haven't done' any diagnosis beyond the diagnostic code attached. here's another small snippet that adds some insight into why isinstance() is failing... (based on the original code)

print([(type(x()), hex(id(type(x()))), x) for x in [Deprecated_, VersionAdded, VersionChanged]])

yields

[(<class '__main__.Deprecated_'>, '0x25fbedad588', <class '__main__.Deprecated_'>), 
(<class '__main__.VersionAdded'>, '0x25fbedabf68', <AdapterWrapper at 0x0000025FC0582208 for type at 0x0000025FBEDABF68>), 
(<class '__main__.VersionChanged'>, '0x25fbedace28', <AdapterWrapper at 0x0000025FC0520438 for type at 0x0000025FBEDACE28>)]

👍 The type of @deprecated class instances is the annotated class.

👎 The type of @versionadded and @versionchanged class instances is a wrapper to the annotated class.

tantale added a commit that referenced this issue Sep 5, 2021
@tantale tantale closed this as completed in 5f051bf Sep 5, 2021
tantale added a commit that referenced this issue Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants