Skip to content

Allow nested placeholders in type alias definitions? #7111

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

Closed
JukkaL opened this issue Jul 1, 2019 · 4 comments
Closed

Allow nested placeholders in type alias definitions? #7111

JukkaL opened this issue Jul 1, 2019 · 4 comments
Labels
feature priority-1-normal semantic-analyzer Problems that happen during semantic analysis topic-type-alias TypeAlias and other type alias issues

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 1, 2019

PR #7091 broke some previously supported uses involving type aliases with the new semantic analyzer, since it doesn't allow nested placeholder types in type alias definitions. Example where this happens (there are other similar test cases; see #7091):

[case testNewAnalyzerAliasToNotReadyDirectBase]
from typing import List

x: B
B = List[C]
class C(B): pass

reveal_type(x)
reveal_type(x[0][0])
[builtins fixtures/list.pyi]
[out]
main:3: error: Cannot resolve name "B" (possible cyclic definition)
main:4: error: Cannot resolve name "B" (possible cyclic definition)
main:4: error: Cannot resolve name "C" (possible cyclic definition)
main:7: note: Revealed type is 'Any'
main:8: note: Revealed type is 'Any'

It would be better if there were no complaints about cyclic definitions and the revealed types were precise.

Support for nested placeholder types was removed since it causes infinite expansions and max iteration count errors. We'd need a way to prevent this to re-enable the feature.

@aviv-ebates
Copy link

Is this:

SomeType = Union[int, List['SomeType']]

error: Cannot resolve name "SomeType" (possible cyclic definition)
Revealed type is 'Union[builtins.int, builtins.list[Any]]'

an instance of this issue?

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jul 26, 2019

@aviv-ebates Your example is a different, since SomeType is defined recursively. There is an existing issue about recursive types: #731.

@antonagestam
Copy link
Contributor

Is this the same issue as #7069 ? My issue should probably be closed if it's the same.

Support for nested placeholder types was removed

Does this mean the old semantic analyzer will be removed before these definitions are handled? It seems like the behavior of an ignored recursive type definition changes drastically between the old/new analyzer. I mostly want to now if we should replace them with e.g. Dict[str, Any] until support for recursive types is in place, or if there will be some non-breaking way to keep the definitions in place until then. :)

@JelleZijlstra JelleZijlstra added the topic-type-alias TypeAlias and other type alias issues label Mar 19, 2022
@ilevkivskyi
Copy link
Member

This was enabled when enabling recursive aliases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature priority-1-normal semantic-analyzer Problems that happen during semantic analysis topic-type-alias TypeAlias and other type alias issues
Projects
None yet
Development

No branches or pull requests

5 participants