Commit Graph

1538 Commits

Author SHA1 Message Date
Jelle Zijlstra 0142a87da8 adjust isort config (#4290)
Fixes #4288.

- Default imports to THIRD_PARTY, so in effect we merge the FIRST_PARTY and THIRD_PARTY stubs. This means import order is no longer affected by whether typing_extensions is installed locally.
- Treat typing_extensions, _typeshed and some others as standard library modules.

Note that isort master is very different from the latest release; we'll have to do something
different if and when the next isort release comes out.
2020-06-29 00:00:21 -07:00
Vishal Kuo cc8344b8c6 [multiprocessing] fixes more incorrect types (#4289) 2020-06-28 16:08:14 -07:00
Sebastian Rittau 4586ed9adc Require black and isort for contributions (#3329)
* Add explanation to CONTRIBUTNG.md
* Add sample pre-commit script
* Check for correctly formatted files in CI

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2020-06-28 15:28:28 -07:00
Jelle Zijlstra 5d553c9584 apply black and isort (#4287)
* apply black and isort

* move some type ignores
2020-06-28 13:31:00 -07:00
Shantanu fe58699ca5 collections/typing: fix various arg names (#4258)
This feels nervous, but if it passes unit tests it's unlikely to break
anything
2020-06-28 12:27:21 -07:00
Denis Laxalde 0dd3258ed2 Add __aiter__ and __anext__ methods for asyncio.StreamReader (#4286)
The following code produces an error in mypy:

    import asyncio
    from asyncio.subprocess import PIPE

    async def main() -> None:
        proc = await asyncio.create_subprocess_shell("ls -l", stdout=PIPE)
        assert proc.stdout is not None
        async for line in proc.stdout:
            print(line.decode())
        await proc.wait()

    asyncio.run(main())

$ mypy --strict file.py
file.py:8: error: "StreamReader" has no attribute "__aiter__" (not async iterable)

This commits fixes this by adding __aiter__/__anext__ methods that are
needed for async iterator protocol.
2020-06-28 11:57:49 -07:00
Vishal Kuo e467fd50ab multiprocessing: add sharedctypes, fix some stubtest cases (#4282) 2020-06-26 23:38:34 -07:00
Shantanu afcb46655a graphlib: add in py39 (#4268)
Co-authored-by: hauntsaninja <>
2020-06-26 20:49:50 +02:00
Shantanu cc150f1d76 compileall: update for py39 again (#4269)
Co-authored-by: hauntsaninja <>
2020-06-26 12:46:18 +02:00
helafumpek 534ebd5051 Change argument type in random.shuffle (python/typeshed#4255) (#4260)
Fixes #4255
2020-06-24 08:17:13 +02:00
Bruce Merry fb398b1d59 Use the ReadableBuffer type in more places (#4245)
This is a follow-up on #4232. memoryview, hashlib, and hmac are updated
to use ReadableBuffer type instead of their own home-spun unions of
bytes, bytearray and whatever else each use case used. mmap is being
handled in #4244, and I'll leave BinaryIO for another day (or possibly
another person) because it's going to require some messy code
duplication because the relevant methods are defined in IO[AnyStr].

There's one corner case I'm not quite sure how best to handle: the
documentation for hmac.digest claim that the parmaeters have the same
meanings as in hmac.new, but in CPython the latter has an explicit check
that `key` is bytes or bytearray while the former works with a
memory-view. For now I've matched the documentation.

Also, the documentation for HMAC.update says that `msg` can be any type
supported by hashlib from Python 3.4; but I can't see anything in the
Python 2.7 implementation that would prevent it also taking bytes-like
objects, so I've not tried to treat Python 2 any different to Python 3.
2020-06-22 06:17:24 -07:00
Jelle Zijlstra e1d89e5742 remove references to "Text" in Python 3-only stubs (#4251) 2020-06-22 12:39:01 +02:00
Milap Sheth 66a9a4b5ce Fix type hint of generator throw method (#4253)
* Fix type hint of generator throw method

* Incorporated changes from #4252
2020-06-21 15:23:28 -07:00
Milap Sheth 9b3edda33b Fix unittest stub issues reported by mypy stubtest (#4248)
Co-authored-by: Shantanu <>
2020-06-21 15:09:17 -07:00
Rune Tynan 79111ee8ed Fix _DispatchProtocol in xmlrpc.server (#4165) 2020-06-21 13:42:14 -07:00
Russell Davis aca6bd7e88 Fix os.exec* and os.spawn* to allow PathLike for all args (#4236) 2020-06-21 13:41:19 -07:00
Sebastian Rittau a615a17976 Update black and work around an isort bug (#4242) 2020-06-19 08:32:05 -07:00
Bruce Merry e05fbabdeb Introduce ReadableBuffer and WriteableBuffer Union aliases (#4232)
Since typing doesn't yet have a way to express buffer protocol objects
(python/typing#593), various interfaces have ended up with a mish-mash
of options: some list just bytes (or just bytearray, when writable),
some include mmap, some include memoryview, I think none of them include
array.array even though it's explicitly mentioned as bytes-like, etc. I
ran into problems because RawIOBase.readinto didn't allow for
memoryview.

To allow for some uniformity until the fundamental issue is resolved,
I've introduced _typeshed.ReadableBuffer and _typeshed.WriteableBuffer,
and applied them in stdlib/3/io.pyi as an example. If these get rolled
out in more places, it will mean that we have only one place where they
have to get tweaked in future, or swapped out for a public protocol.

This unfortunately does have the potential to break code that inherits
from RawIOBase/BufferedIOBase and overrides these methods, because the
base method is now more general and so the override now needs to accept
these types as well (which is why I've also updated gzip and lzma).
However, it should be a reasonably easy fix, and will make the
downstream annotations more correct.
2020-06-19 12:45:12 +02:00
Martijn Pieters 5c739ef4c3 os.fsencode(PathLike[AnyStr]) produces AnyStr (#4233)
PathLike is generic over AnyStr of 7587e7f1c1. Also see 89de36afa4, which changed this to `Any` before `AnyStr` was available.
2020-06-16 15:57:58 -07:00
Sebastian Rittau 51cf2f51b8 Add IO protocols to _typeshed (#4230) 2020-06-14 20:44:48 +02:00
Sebastian Rittau 89d3a55f1a Preparations for the Big Reformat (#4228)
A few comments between imports were removed or moved to the top of the
import block, due to behavioral differences between black and isort. See
psf/black#251 for details.

In two instances @overloads at the top of the file needed to be moved
due to psf/black#1490.
2020-06-14 07:58:26 -07:00
Jelle Zijlstra 8100c0be89 subprocess: use AnyPath (#4218) 2020-06-11 09:15:10 +02:00
Jelle Zijlstra d0b85d7efe remove _types (#4220) 2020-06-11 09:10:52 +02:00
Jelle Zijlstra 44a852dff5 Literal: always import from typing_extensions for simplicity (#4219) 2020-06-10 21:23:58 -07:00
Jelle Zijlstra 43e93f803f use _typeshed's Path aliases (#4214) 2020-06-10 20:57:09 -07:00
Jelle Zijlstra d261f14886 add constructors for configparser errors (#4215)
Fixes #4058

Co-authored-by: Shantanu <hauntsaninja@users.noreply.github.com>
2020-06-10 12:32:18 -07:00
Jelle Zijlstra ea577cec1f move OpenTextMode and friends to _typeshed (#4213) 2020-06-10 15:36:21 +02:00
Mikhail Golubev 85281b636e Add __class_getitem__ to builtins generified in PEP 585 (#4184)
* Add __class_getitem__ to builtins generified in PEP 585

* Declare types.GenericAlias and use it in __class_getitem__
2020-06-09 20:10:07 -07:00
Sebastian Rittau afe1e543b3 Make multiprocessing.Namespace accept any attribute (#4204)
Update multiprocessing.dummy.Namespace as well

Closes: #4186
2020-06-09 12:34:36 -07:00
Shantanu 72c8907760 tkinter: fix version availability (#4207)
Co-authored-by: hauntsaninja <>
2020-06-09 12:20:48 +02:00
Sam Bull 5f70d3721a Update root dbm module. (#4199) 2020-06-09 12:20:09 +02:00
Sebastian Rittau 206bff44ed Remove BinaryIO.write() (#4203)
write() is inherited from IO[bytes], where it's defined as
`def write(self, s: AnyStr) -> int: ...`. If AnyStr is bytes,
this should accept bytes, bytearray, and memoryview, so the
overload is unnecessary.

Closes: #4201
2020-06-08 13:40:41 -07:00
Christopher Head 51267a4b12 Add tkinter Event class (#4200) 2020-06-08 12:46:16 -07:00
Jaromir Latal c36e4517f7 [stdlib][asyncio] Accept optional context in (Timer)Handle (#4190) 2020-06-07 06:33:46 -07:00
Christopher Head 948c1a63e6 Relax asyncio.TimerHandle.__init__ args parameter (#4193)
Just like the Handle class, the TimerHandle class can take any sequence
here, not just a list.
2020-06-06 18:33:23 -07:00
Christopher Head 7931635b52 Add sys.{get,set}_asyncgen_hooks (#4195) 2020-06-06 15:44:48 -07:00
Christopher Head 5b36051f77 tkinter: fix variable parameter to wait_variable (#4194)
The tkinter `wait_variable` function can be called with either the name
of a variable (a `str`) or an actual variable object (a `Variable`).
2020-06-06 14:41:42 -07:00
Eric N. Vander Weele 4199352287 Fix typing.ForwardRef.__eq__ stub (#4177)
The return type of `__eq___` should be `bool`.

Otherwise, `mypy --disallow-any-unimported --no-silence-site-packages`
fails because the return type becomes `Union[bool, Any]` due to an
unfollowed import.
2020-06-06 08:04:05 -07:00
Jaromir Latal 9ab4ec568d [stdlib][asyncio] Widen asyncio.events.handle arguments type (#4188)
Co-authored-by: Jaromir Latal <jaro@fb.com>
2020-06-06 16:48:02 +02:00
Jaromir Latal 52bf411f2b [stdlib][asyncio] Allow optional policy in (#4189)
Co-authored-by: Jaromir Latal <jaro@fb.com>
2020-06-06 16:47:04 +02:00
Sam Bull 5b66868156 Allow Path in create_subprocess_* (#4159) 2020-06-04 17:11:53 +02:00
Sebastian Rittau a913af9523 flake8: Enable F811 (#4158) 2020-06-02 14:08:54 -07:00
Kevin Wojniak 17aa20cd95 Add st_file_attributes to stat_result for Windows (#4156)
This member is documented at https://docs.python.org/3/library/os.html#os.stat_result.st_file_attributes and https://docs.python.org/3/whatsnew/3.5.html#os

Co-authored-by: hauntsaninja <>
2020-06-01 23:53:11 -07:00
Rune Tynan 342ce69f88 Add missing asyncio modules (#4149) 2020-06-01 02:05:16 +02:00
Jelle Zijlstra adeda24fce open: introduce concrete return types (#4146)
* make io classes inherit from typing IO classes

This makes these classes usable if type annotations are given as "IO"
or "TextIO". In the future, we'll then be able to move open() to
return a concrete class instead (#3951).

* open: introduce concrete return types

Fixes #3951.

We use the values of the "mode" and "buffering" arguments to figure out
the concrete type open() will return at runtime. (Compare the CPython
code in https://github.com/python/cpython/blob/master/Modules/_io/_iomodule.c#L231.)
2020-06-01 00:48:12 +02:00
Rune Tynan d863210335 Improve TypeVar stub (#4150) 2020-05-30 20:27:59 -07:00
Jelle Zijlstra 3058bec873 make io classes inherit from typing IO classes (#4145)
This makes these classes usable if type annotations are given as "IO"
or "TextIO". In the future, we'll then be able to move open() to
return a concrete class instead (#3951).
2020-05-30 06:50:49 -07:00
Shantanu de2c2947fe windows: fix splitunc param name (#4143)
Co-authored-by: hauntsaninja <>
2020-05-29 20:37:19 -04:00
Rune Tynan 4381eba6f4 Add _sitebuiltins stubs (#4139) 2020-05-29 22:33:06 +02:00
Rune Tynan d035ce57e3 Add platform checks for various sys values (#4137)
* Add platform checks for various sys values

* Add windows-only constants
2020-05-28 19:00:31 -07:00