-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Removes a lot of unused code #11698
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
Removes a lot of unused code #11698
Changes from all commits
Commits
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
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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -903,6 +903,31 @@ class Instance(ProperType): | |
"""An instance type of form C[T1, ..., Tn]. | ||
|
||
The list of type variables may be empty. | ||
|
||
Several types has fallbacks to `Instance`. Why? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
Because, for example `TupleTuple` is related to `builtins.tuple` instance. | ||
And `FunctionLike` has `builtins.function` fallback. | ||
This allows us to use types defined | ||
in typeshed for our "special" and more precise types. | ||
|
||
We used to have this helper function to get a fallback from different types. | ||
Note, that it might be incomplete, since it is not used and not updated. | ||
It just illustrates the concept: | ||
|
||
def try_getting_instance_fallback(typ: ProperType) -> Optional[Instance]: | ||
'''Returns the Instance fallback for this type if one exists or None.''' | ||
if isinstance(typ, Instance): | ||
return typ | ||
elif isinstance(typ, TupleType): | ||
return tuple_fallback(typ) | ||
elif isinstance(typ, TypedDictType): | ||
return typ.fallback | ||
elif isinstance(typ, FunctionLike): | ||
return typ.fallback | ||
elif isinstance(typ, LiteralType): | ||
return typ.fallback | ||
return None | ||
|
||
""" | ||
|
||
__slots__ = ('type', 'args', 'erased', 'invalid', 'type_ref', 'last_known_value') | ||
|
@@ -1033,10 +1058,11 @@ class FunctionLike(ProperType): | |
|
||
__slots__ = ('fallback',) | ||
|
||
fallback: Instance | ||
|
||
def __init__(self, line: int = -1, column: int = -1) -> None: | ||
super().__init__(line, column) | ||
self.can_be_false = False | ||
self.fallback: Instance | ||
|
||
@abstractmethod | ||
def is_type_obj(self) -> bool: pass | ||
|
@@ -1639,7 +1665,7 @@ def copy_modified(self, *, fallback: Optional[Instance] = None, | |
required_keys = self.required_keys | ||
return TypedDictType(items, required_keys, fallback, self.line, self.column) | ||
|
||
def create_anonymous_fallback(self, *, value_type: Type) -> Instance: | ||
def create_anonymous_fallback(self) -> Instance: | ||
anonymous = self.as_anonymous() | ||
return anonymous.fallback | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it used in some important place? Or is it popular in plugin code? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally speaking, this func helped me understand the effects of
fallback
and related code structure in mypy when I was a new contributorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@97littleleaf11 we can try to solve this via docs. Probably I can copy paste this function into some docstring. Thanks a lot for the idea! 👍