Open pritsh opened 2 years ago
Hi, I just stumbled across this issue because I noticed the same problem. While I don't know what exactly causes the problem, I know at least why you get this result. The reason is because the original classes are still contained in the list returned by GenType.__subclasses__()
. (Weirdly enough, the problem with your code example occurs for me only for class TypeTwo
, but I experienced similar behavior in my own code).
What I get as an output is [__main__.TypeOne, __main__.TypeTwo, __main__.TypeTwo]
, where you can see that the class appears twice (in your case, you'll probably also see the same for TypeOne
, causing your error). If you select from the list the second version of the class, your example will probably work.
However, I don't know the root cause for the problem, but it might have something to do with garbage collection!? On the attrs page, there is a hint related to slotted classes:
which points to this issue: https://github.com/python-attrs/attrs/issues/407
Also, it seems somehow related to the Union
call because in my cases the duplicates only appeared after the call. Any idea here?
Anyway, the clean way to do it is described here: #140 Hope this helps 👍
Description
Thanks for this amazing library !!
I am trying to write disambiguation function to handle union type based on the default value of child class but got into weird error, also want to understand the correct way to do it with cattrs.