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

4.6.0 and later break TensorFlow 2.12.0 with Python 3.8 #216

Closed
stewartmiles opened this issue Jun 2, 2023 · 2 comments
Closed

4.6.0 and later break TensorFlow 2.12.0 with Python 3.8 #216

stewartmiles opened this issue Jun 2, 2023 · 2 comments

Comments

@stewartmiles
Copy link

It's possible TensorFlow is doing something wrong or typing_extensions is at fault 🤷🏽

dfe4889 appears to be the culprit.

Here's a way to reproduce after installing TensorFlow 2.12.0

from tensorflow.python.trackable import data_structures
from tensorflow.python.types import trace

standard_dict = {'foo': 'bar'}
wrapped_dict = data_structures._DictWrapper(standard_dict)

# Prints False
print(isinstance(standard_dict, trace.SupportsTracingProtocol))

# The following line throws "TypeError: this __dict__ descriptor does not support '_DictWrapper' objects"
print(isinstance(wrapped_dict, trace.SupportsTracingProtocol))

i.e, running the above spits out the following:

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    print(isinstance(wrapped_dict, trace.SupportsTracingProtocol))
  File "/home/xxx/src/.venv/lib/python3.8/site-packages/typing_extensions.py", line 605, in __instancecheck__
    val = inspect.getattr_static(instance, attr)
  File "/usr/lib/python3.8/inspect.py", line 1596, in getattr_static
    instance_result = _check_instance(obj, attr)
  File "/usr/lib/python3.8/inspect.py", line 1543, in _check_instance
    instance_dict = object.__getattribute__(obj, "__dict__")
TypeError: this __dict__ descriptor does not support '_DictWrapper' objects
@stewartmiles
Copy link
Author

Oh ok it looks like folks are tracking this on the TensorFlow repo tensorflow/tensorflow#60687 it appears to be an issue with TensorFlow.

@AlexWaygood
Copy link
Member

AlexWaygood commented Jun 2, 2023

Looks to me like it's probably an issue with wrapt rather than typing_extensions or TensorFlow, actually. We discussed this a bit in python/cpython#105134.

Wrapt raises TypeError if you do object.__getattribute__(<some_wrapt_ObjectProxy_instance, '__dict__'). I know of no way to construct a class using pure Python that has this behaviour (wrapt achieves this behaviour by using a C extension), and it breaks some fundamental assumptions that the stdlib function inspect.getattr_static makes. That, in turn, breaks typing_extensions.

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

No branches or pull requests

2 participants