protocol, overloads to list.sort, sorted; WIP to fix #4051 (replaces #4155)#4192
Merged
JelleZijlstra merged 1 commit intopython:masterfrom Jun 7, 2020
ramalho:master
Merged
protocol, overloads to list.sort, sorted; WIP to fix #4051 (replaces #4155)#4192JelleZijlstra merged 1 commit intopython:masterfrom ramalho:master
JelleZijlstra merged 1 commit intopython:masterfrom
ramalho:master
Conversation
JelleZijlstra
approved these changes
Jun 7, 2020
grievejia
added a commit
to grievejia/typeshed
that referenced
this pull request
Jun 25, 2020
PEP 544 intentionally did not specify whether method conformance check in protocol inference should look at parameter names. For example, it's up to the type checker to decide whether a class with method defined as `def foo(self, x: int)` would implement a protocol with method `def foo(self, y: int)`. Mypy decided to ignore parameter names altogether, but we Pyre team decided to be more strict and refuse to match different parameter names (as it is unsound to do so when those methods are invoked with named parameters). Since Pyre also rely on the typeshed stubs, we want to make sure at least the important stubs on typeshed conform to our standard. This PR changes `_SupportsLessThan.__lt__` (introduced in python#4192) to use dunder (i.e. positional-only) parameter name specified in PEP484. This change should not affect mypy since it ignores parameter names, but will make Pyre happy when builtin functions like `sorted` is used. Note there are likely to be other cases where we might want this. We'll submit subsequent PRs in a demand-driven fashion.
vishalkuo
pushed a commit
to vishalkuo/typeshed
that referenced
this pull request
Jun 26, 2020
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
(I am sorry to create another PR, but I made the mistake of deleting the fork of typeshed that I had when I started this work, and I could not find a way to tell Github to continue the previous PR #4155.)
This PR introduces the
_SupportsLessThanprotocol and a type variable bounded to it to check arguments tolist.sortandsortedon Python 3 (on Python 2, everything supports__lt__, evenNoneandobject).When this PR is merged, I will send another one using
_SupportsLessThanto check arguments to min and max, fixing #4051 with several overloads.