question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

An issue with forward declarations and recursive type

See original GitHub issue

Example:

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:open
  • Created 6 years ago
  • Comments:25 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
Steworicommented, Jan 2, 2018

I think Union + forward declarations.

I mean are there examples without Union, i.e. is this issue specific to Union checking or do we have to think more general?

Are you sure? Keeping track might introduce additional performance cost. But from design perspective this is probably cleaner, yes.

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.

1reaction
mitarcommented, Dec 24, 2017

You are amazing! I will check it immediately!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found