-
Notifications
You must be signed in to change notification settings - Fork 231
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
ObjectProxy does not play well with GenericAlias, such as isinstance(proxy, Dict) #245
Comments
What is the I am not familiar with Even so, the code |
In general, you can't check if values are instances of generic aliases. It should raise |
Hey Graham, So, for Dict, it is coming I also just found this ticket in CPython: python/cpython#89949 |
To better understand implication of Paul's comment about |
Some code to help illustrate:
|
Yeah, was hoping for better example from Alexandre to see whether that sort of change you were suggesting made sense. FWIW, I didn't even know you could write something like |
Generic aliases from base types is relatively new. I believe circa 3.10. Prior to that, we had to use generics defined in |
I think @pbryan argument is fair enough. I think as long as this happens in code I own / have control over this is pretty easy to fix / handle by moving to checks against the proper classes, rather than the aliases. Less so if it happens in libraries. I am checking a few corner cases before committing on using the proxy more widely. |
As far as sniff test on the code:
I still feel it isn't favourable to duck typing and perhaps could be rewritten as:
Obviously this would help with the weird goals of With the demise of Twitter I don't know of an easy way to reach out to any Python folks who may have an opinion. :-( |
Oh, and could well be the |
...... Twitter.... Some devs seem to agree there if I understand correctly python/cpython#89949 . Also not sure how much it actually matters, and it may be a dangerous change |
Thanks for the help. Looks like I will have to be careful using the proxy. It seems that CPython's This causes issue with C implementations, even in the standard lib. For example, when trying to Json-serialize a proxy: def test_can_json_serialize_proxy():
import json
p = wrapt.ObjectProxy((1, 2, 3))
serialized = json.loads(json.dumps(p))
assert serialized == (1, 2, 3) This will fail here, when CPython relies on the C library Interestingly enough the python implementation of it is fine and uses isinstance. |
Thanks for the great library!
Just ran into an issue with instance checks on typing.py aliases.
This is due to GenericAlias / _BaseGenericAlias being implemented as:
I imagine this is a python bug? Is this something you have run into before?
The text was updated successfully, but these errors were encountered: