-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Implementing background infrastructure for recursive types: Part 3 #7885
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1b94014
Start adding visitor methods
ilevkivskyi ecc515e
Add some visitors
ilevkivskyi a8fb527
Merge remote-tracking branch 'upstream/master' into recursive-types
6b689fa
Add some simple visitor_methods
f37f288
Add fixup visitor
3ae2fe4
few more visitors
c32075b
Add subtype visitors
c12234e
Cache is_recursive
99ab1af
Fix slots
4a54904
Merge remote-tracking branch 'upstream/master' into recursive-types
c610fc9
Address CR
0f7c9aa
Clean-up alias expansion
56d4424
Allow non-proper types as union items
3640d92
Shift proper subtype logic and add some tests
1a17a9d
Fix lint
321d6f2
Fix typo
655aee2
Merge remote-tracking branch 'upstream/master' into recursive-types
fa586d1
Make constraints consistent with subtypes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add subtype visitors
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
8000
|
@@ -7,7 +7,7 @@ | |
CallableType, Type, TypeVisitor, UnboundType, AnyType, NoneType, TypeVarType, Instance, | ||
TupleType, TypedDictType, UnionType, Overloaded, ErasedType, PartialType, DeletedType, | ||
UninhabitedType, TypeType, TypeVarId, TypeQuery, is_named_instance, TypeOfAny, LiteralType, | ||
ProperType, get_proper_type | ||
ProperType, get_proper_type, TypeAliasType | ||
) | ||
from mypy.maptype import map_instance_to_supertype | ||
import mypy.subtypes | ||
|
@@ -89,6 +89,22 @@ def infer_constraints(template: Type, actual: Type, | |
|
||
The constraints are represented as Constraint objects. | ||
""" | ||
if (isinstance(template, TypeAliasType) and isinstance(actual, TypeAliasType) and | ||
template.is_recursive and actual.is_recursive): | ||
# This case requires special care because it may cause infinite recursion. | ||
assert template.alias is not None | ||
if any(mypy.sametypes.is_same_type(template, t) for t in template.alias.inferring): | ||
return [] | ||
template.alias.inferring.append(template) | ||
res = _infer_constraints(template, actual, direction) | ||
template.alias.inferring.pop() | ||
return res | ||
return _infer_constraints(template, actual, direction) | ||
|
||
|
||
def _infer_constraints(template: Type, actual: Type, | ||
direction: int) -> List[Constraint]: | ||
|
||
template = get_proper_type(template) | ||
actual = get_proper_type(actual) | ||
|
||
|
@@ -485,6 +501,9 @@ def visit_union_type(self, template: UnionType) -> List[Constraint]: | |
assert False, ("Unexpected UnionType in ConstraintBuilderVisitor" | ||
" (should have been handled in infer_constraints)") | ||
|
||
def visit_type_alias_type(self, template: TypeAliasType) -> List[Constraint]: | ||
assert False, "This should be never called, got {}".format(template) | ||
|
||
def infer_against_any(self, types: Iterable[Type], any_type: AnyType) -> List[Constraint]: | ||
res = [] # type: List[Constraint] | ||
for t in types: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.