An issue with forward declarations and recursive type
See original GitHub issueExample:
import typing
from pytypes import type_util
Container = typing.Union[
typing.List['Data'],
]
Data = typing.Union[
Container,
str, bytes, bool, float, int, dict,
]
type_util._issubclass(typing.List[float], Container)
Traceback (most recent call last):
File "<redacted>/lib/python3.6/site-packages/pytypes/type_util.py", line 1387, in _issubclass_2
return issubclass(subclass, superclass)
TypeError: Forward references cannot be used with issubclass().
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 14, in <module>
type_util._issubclass(typing.List[float], Container)
TypeError: Invalid type declaration: float, _ForwardRef('Data')
Issue Analytics
- State:
- Created 6 years ago
- Comments:25 (11 by maintainers)
Top Results From Across the Web
Forward declaration incomplete type, recursive - c++
I have a vector of pointers to Observer, in Subject class, I forward declared Obsever class and Observer class knows about Subect, why...
Read more >Forward Declarations - Oracle PL/SQL Programming ... - O'Reilly
The following example illustrates the technique of forward declaration. I define two mutually recursive functions within a procedure. Consequently, I have ...
Read more >Forward declaration - Wikipedia
In computer programming, a forward declaration is a declaration of an identifier for which the programmer has not yet given a complete definition....
Read more >Forward declaration of types. - New to Julia
I would like to define a set of mutually recursive types. ... mutually-circular type declarations · Issue #269 · JuliaLang/julia · GitHub, but...
Read more >Forward declaration VS compiling order error in c++ to avoid ...
[Solved]-Forward declaration VS compiling order error in c++ to avoid recursive header inclusion-C++ · use include guard · forward declare class A, and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I mean are there examples without
Union
, i.e. is this issue specific toUnion
checking or do we have to think more general?My philosophy in
pytypes
is to allow user to opt out of such arguable stuff. Aside that I value correctness higher than performance (in production, one would disable typechecking anyway I suppose). Also, that’s why I think of a fast-succeed mode.You are amazing! I will check it immediately!