-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Merge bisect #468
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
Merge bisect #468
Conversation
|
||
def bisect_left(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...): pass | ||
def bisect_right(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...): pass | ||
def bisect_left(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... |
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.
It's perfectly legal for x
to not be in a
.
For example,
bisect.bisect_left([1,2,3], None)
is valid code. (And bisect_left will just return 0
in this case)
So the type parameter here is overkill.
That seems a 2/3 difference though -- in PY3 |
But even Python 3 allows
which is still a type error for
|
But do you have code that relies on that? Usually a bisect() call is followed by an insert() at the found position, and inserting 5.391 into a List[int] is a type error. So I still prefer the PR as-is here rather than the original |
In pysco, I found the little gem
In our codebase, I'm also seeing a few occurences of the pattern I know it's tempting to use typeshed to define APIs the way we think they should be used, rather than how people are currently using them. But let's resist that and model the real world. |
Hmm I think that
Since |
Tried your suggestion in mypy, but got:
|
That looks like a mypy bug to me (filed python/mypy#2035). |
The mypy bug won't be fixed soon (it's a bit tricky). Can you either put a |
Gone for a TODO and using |
https://docs.python.org/3/library/bisect.html