third_party/2/concurrent/futures is for the Python 2 backport of the
concurrent.futures package from Python 3. In Python 3, all exceptions
are derived from BaseException, but Python 2 also supports exceptions
that are old-style objects (which don't derive from BaseException).
Switch from BaseException to Any to allow old-style exceptions.
All old-style objects are instances of types.InstanceType, so an
alternative to Any is Union[BaseException, types.InstanceType]. This
would help avoid accidentally passing a non-BaseException new-style
object to Future.set_exception(). However, only Executors call that
function (usually), and it's not clear that mypy understands old-style
objects and their relationship to types.InstanceType, so Any is
thought to be the more practical choice.
"> (3,)" works but looks like the code is checking for Python 4.
"<= (3, 5)" was intended to check for versions up to and including 3.5, and probably works that
way in current type checkers. However, sys.version_info is actually a 5-tuple that is greater
than (3, 5), so a hypothetical type checker that uses the full version info would interpret
this check incorrectly.
This ensures that all version_info comparisons use <, >=, ==, or !=.
Closes#953.
I reviewed the documentation at https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop and added missing methods and missing @coroutine decorators.
I ran mypy on the sample file from the issue report to confirm that mypy handles the combination of @abstractmethod and @coroutine correctly.
Also fixed a number of types in this file that are annotated as Any but could be given more precise types (e.g., sockets and protocol factories).
Both mypy and pytype only use the major and minor version in type checking. Using
checks like "sys.version_info >= (3, 4, 4)" won't actually work properly for
people type checking their code using version 3.4, because (3, 4) >= (3, 4, 4) will
always be false (at least in mypy's approach; not sure if pytype is different).
Fixes#975
And a few more things I noticed while reading the tempfile docs.
In 3.5, most functions in tempfile were changed to accept either str or bytes in their prefix and suffix arguments, and return bytes or str accordingly. This seemed like a case for AnyStr.
We were missing tempdirb and tempprefixb, added in 3.5.
TemporaryFile and others were declared as returning BinaryIO, but they actually return either binary or text IO depending on the mode passed in. I changed the return type to IO[Any], similar to builtins.open.
* Make pickle accept IO[str] instead of BinaryIO.
This makes the following code work:
pickle.Unpickler(cStringIO.StringIO())
(Which didn't work before because cStringIO.StringIO inherits "only"
from IO[str], not BinaryIO)
* Use bytes instead of str.
I've seen some stubs like
```
class X:
def __init__(self, x: str) -> None:
self.x = x
self.y = 0
```
I think this should be written instead as
```
class X:
x: str
y: int
def __init__(self, x: str) -> None: ...
```
* Fix a few return types in stdlib/2/inspect.pyi.
* Rename _FrameRecord to _FrameInfo
* Correct some return types in itertools.pyi from Iterable to Iterator.
* Improve types for xml.etree.ElementTree
Update signatures to reflect the following peculiarities of the
ElementTree library:
- The elementtree library accepts unicode or bytes for most xml values
in python2, and coerces everywhere -- but in python3, only str makes
sense.
- In python 2, the library produces str or unicode instances
unpredictably, depending on whether the xml is decodeable as ascii or
not. In python 3, it always produces str instances.
- The parser functions accept unicode or bytes in 2 and 3 -- again, will
coerce individual instances so heterogeneous lists are ok.
- In python 3, the tostring functions produce bytes or str, depending on
the value of the 'encoding' parameter.
* improve docs
* Improve ElementFactory type by specifying dict of 2nd arg
Mypy now supports metaclasses in Python 2, see python/mypy#2830
so that now __metaclass__ attribute has special treatment.
This PR makes small changes to fix the build (also most PRs are red because of this)