Technically this is a lie, since we return a heterogeneous iterator, not
a tuple. But since we don't have a way of typing heterogeneous
iterators, this is the best we can do.
Fixes https://github.com/python/mypy/issues/8454
The Python source (Objects/exceptions.c) explicitly checks for null
pointers before using the filename and lineno members. Some libraries,
e.g. pkg_resources, set filename and lineno to undefined values if
indeed none are appropriate.
`int.from_bytes` supports both iterables of ints and objects that define
__bytes__'. As an example `int.from_bytes(iter([1, 0]), 'little'))`
returns 1.
This is a continuation of #3291, which was the initial fix for #3201.
The 2-arg version of iter() turns a callable into an iterator. The
changes made in #3291 introduce an Any return type for both the
callable's return type and the iterator's type, while in reality the
return type of the function is always the same as the iterator's type.
Modified __add__ method in tuple class to allow it to accept tuples with different generic parameter types. This allows, for example:
a = (1, )
b = a + (2.4, )
This pull request is a follow-up to https://github.com/python/mypy/issues/7214.
In short, within that mypy issue, we found it would be helpful to
determine between contextmanagers that can "swallow" exceptions vs ones
that can't. This helps prevent some false positive when using flags that
analyze control flow such as `--warn-unreachable`. To do this,
Jelle proposed assuming that only contextmanagers where the `__exit__`
returns `bool` are assumed to swallow exceptions.
This unfortunately required the following typeshed changes:
1. The typing.IO, threading.Lock, and concurrent.futures.Executor
were all modified so `__exit__` returns `Optional[None]` instead
of None -- along with all of their subclasses.
I believe these three types are meant to be subclassed, so I felt
picking the more general type was correct.
2. There were also a few concrete types (e.g. see socketserver,
subprocess, ftplib...) that I modified to return `None` -- I checked
the source code, and these all seem to return None (and don't appear
to be meant to be subclassable).
3. contextlib.suppress was changed to return bool. I also double-checked
the unittest modules and modified a subset of those contextmanagers,
leaving ones like `_AssertRaisesContext` alone.
Per the docs, globals/locals is an optional argument.
Additionally, globals/locals can be any mapping type, not only a dict.
Likewise, fromlist can be any sequence (the docs mention a tuple, not a
list).
The function returns a ModuleType, not Any.
The following code works:
>>> print(sys.version)
2.7.16 (default, Mar 11 2019, 18:59:25)
>>> def f(): pass
>>> print(f.__code__)
<code object f at 0x7f8534ecc8a0, file "<stdin>", line 1>
>>> isinstance(f.__code__, types.CodeType)
True
but it didn't type-check with `mypy --python-version 2.7`.
In python 3, add an overload for there being no digits argument
and make it return int.
In python 2, __round__ doesn't exist and SupportsRound doesn't exist
in the typing module. Use SupportsFloat for python 2 round().
Remove decimal's __round__ overload that takes None, since it doesn't exist