* fix type for TestCase.assertIn
This does essentially `assert member in container`, so we want a `Container`, not an `Iterable`.
This came up in 68e9d426a8..0bbee43d60 (r192525658).
* use any for assertIn
The type signature of get_grouped_opcodes() was incorrect. Resulting in type errors when checking return values.
The usage of this function is like this:
groups = sm.get_grouped_opcodes() # groups is Iterable[List[Tuple[str, int, int, int, int]]]
for group in groups: # group is List[Tuple[str, int, int, int, int]]
for opcode in group: # opcode is Tuple[str, int, int, int, int]
The dict stub was referring to an instance, not the type, leading to
__call__ being considered when using as a decorator, rather than
__init__.
mock is a backport of the stdlib module and should be defined the same.
* Add OpenDirector.addheaders and replace type comments with annotations
* Use ClassVar/eliminate `= ...` and add BaseHandler.handler_order (exists in Py2 versions)
* Use typing.Text
* Add InputStream and ErrorStream WSGI protocols
* Fix return type of WSGIApplication
* Add type hints to wsgiref.validate
* Replace _Bytes by plain bytes
* Add wsgiref.util
* Add wsgiref.headers
* ErrorWrapper.writelines() takes an Iterable
* Fix start_response return type
* Make Python 2 and 3 branches resemble each other more closely
* Use typing.NoReturn
* Fix WriteWrapper.writer type
* Change return type of WriteWrapper.writer to Any
Standard implementation is:
```
def process(self, msg, kwargs):
kwargs["extra"] = self.extra
return msg, kwargs
```
so the signature is clearly `(Text, ...) -> (Text, ...)` (or `(str, ...) -> (str, ...)`, but following the other stubs here, I gather it's `Text`).
Basically, the same thing as [my previous pull request][0], except the
fixes are now focusing on functions with overlapping argument counts.
[0]: https://github.com/python/typeshed/pull/2138
This commit reorders any overloads where the first overload was
"shadowing" the second, preventing it from ever being matched by type
checkers that work by selecting the first matching overload alternative.
For example, the first overload alternative below is strictly broader
then the second, preventing it from ever being selected:
class Parent: pass
class Child(Parent): pass
@overload
def foo(x: *int) -> Parent: ...
@overload
def foo(x: int, y: int) -> Child: ...
The correct thing to do is to either delete the second overload or
rearrange them to look like this:
@overload
def foo(x: int, y: int) -> Child: ...
@overload
def foo(x: *int) -> Parent: ...
Rationale: I'm currently [working on a proposal][0] that would amend
PEP 484 to (a) mandate type checkers check overloads in order and
(b) prohibit overloads where an earlier alternative completely shadows
a later one.
[0]: https://github.com/python/typing/issues/253#issuecomment-389262904
This would prohibit overloads that look like the example below, where
the first alternative completely shadows the second.
I figured it would be a good idea to make these changes ahead of time:
if my proposal is accepted, it'd make the transition smoother. If not,
this is hopefully a relatively harmless change.
Note: I think some of these overloads could be simplified (e.g.
`reversed(...)`), but I mostly stuck with rearranging them in case I was
wrong. The only overload I actually changed was `hmac.compare_digest` --
I believe the Python 2 version actually accepts unicode.
Fixes#1997, #2068.
This is tricky because we need to get the return values right (see #1960 for
prior attempts) and we often run into python/mypy#3644. I found that I
could express most signatures correctly using a series of overloads.
A few other changes in here:
- Added splitunc, which according to https://docs.python.org/3/library/os.path.html
should exist in both Unix and Windows.
- Made the second argument to os.path.curdir Optional to match the implementation.
- Fixed os.path.split, whose previous Path-aware signature triggered python/mypy#3644.
In Python 3, the ndigits argument of round() defaults to None. If
ndigits is excluded or explicitly None, the result is always an int. If
ndigits is not None, the result should be the same type as the number.
$ cat test.py
from fractions import Fraction
print(type(round(0.1)))
print(type(round(0.1, None)))
print(type(round(0.1, 0)))
print(type(round(Fraction(1, 10))))
print(type(round(Fraction(1, 10), None)))
print(type(round(Fraction(1, 10), 0)))
$ python3 ./test.py
<class 'int'>
<class 'int'>
<class 'float'>
<class 'int'>
<class 'int'>
<class 'fractions.Fraction'>
Update the signatures to allow for an ndigits of None.
Fixes#1961.
I mostly just replaced all str annotations with Text, including in return types. This is
only broadly correct; diffing a str and a unicode sequence actually results in a mixed
output of str and unicode. We could also keep the return types as str if using Text
causes errors in real code. For callbacks that take str, I introduced a Union alias
because a callable taking a str would not be a compatible with a parameter of type
Callable[[Text], bool].
I also fixed the return type of difflib.restore.