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 think caching should cache only identical generic types, not equivalent generic types.
In our case this is a problem because we inspect types and generate JSON description of types. And now it is happening that JSON descriptions are changing (because order of values in Union is changing) depending on the order of code loading and which generic type is loaded first during runtime.
The text was updated successfully, but these errors were encountered:
I would say if your code depends on Union[str, int] and Union[int, str] being different, then there is something wrong with your code. It is standard to cache by __eq__/__hash__, I have never seen caching by is, also it is not something new, I believe types were cached like this since late 2016.
Sure, but then cache also Union[int, None], so that Union[int, None] is Union[None, int] equals True. I do not mind either way. But currently some types go one way and other types go another.
This is as expected:
When order is not the same, types are equivalent, but not identical.
But, when used inside generic, then a surprise happens:
The issue is that the first instance of
List[Union[int, None]]
is cached and returned forList[Union[None, int]]
as well. So:I think caching should cache only identical generic types, not equivalent generic types.
In our case this is a problem because we inspect types and generate JSON description of types. And now it is happening that JSON descriptions are changing (because order of values in
Union
is changing) depending on the order of code loading and which generic type is loaded first during runtime.The text was updated successfully, but these errors were encountered: