Commit Graph

871 Commits

Author SHA1 Message Date
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
Peter Law
ed04d33def Make redirect_std{out,err} yield new stream as context var (#4285)
This matches the implementation, even though this behaviour isn't
actually documented yet. https://bugs.python.org/issue41147 aims
to fix the documentation issue though.

Fixes https://github.com/python/typeshed/issues/4283.
2020-06-28 07:36:09 -07:00
Sebastian Rittau
564a8220f4 Add float.__ceil__ and __floor__ (#4274)
Closes: #3195
2020-06-26 22:26:39 -07:00
Shantanu
64327e02e9 keyword: update for py39 (#4272) 2020-06-26 20:50:16 +02:00
Shantanu
9a16b02187 argparse: fix for latest py39 (#4267)
https://github.com/python/typeshed/pull/4144 and
https://github.com/python/cpython/pull/11478#pullrequestreview-423968410
resulted in the issue being fixed upstream.


Co-authored-by: hauntsaninja <>
2020-06-26 12:55:23 +02:00
Shantanu
fc8b0ed94e builtins: remove __class_getitem__ from type (#4270)
Co-authored-by: hauntsaninja <>
2020-06-26 12:45:22 +02:00
Shantanu
2ba6939788 imaplib: update for py39 (#4271) 2020-06-26 12:40:27 +02:00
Shantanu
1c3f526fbf pickle: improve positional-arg accuracy in py39 and others (#4273)
Although technically data in loads is not positional-only in py38, but
we decided that that doesn't matter

Co-authored-by: hauntsaninja <>
2020-06-26 12:29:47 +02:00
Jia Chen
92fa4e799c Using dunder parameter name in builtins._SupportsLessThan (#4264) 2020-06-25 21:02:00 +02:00
Shantanu
70459abb44 Revert "zip: add some overloads for heterogeneous tuples (#3830)" (#4254)
This reverts commit e857ad6ba9.

Co-authored-by: hauntsaninja <>
2020-06-25 08:46:02 -07:00
Milap Sheth
14af8790f3 Added missing properties to struct_time (#4256) 2020-06-22 20:43:53 -07: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
Bruce Merry
ec6116dfa4 Update mmap stubs for newer Python versions (#4244)
* Update mmap stubs for newer Python versions

Based on the Python stdlib documentation:
- Since Python 3.5, mmap.{find,rfind,write} all accept any bytes-like.
  I've used the _typeshed.ReadableBuffer alias defined in #4232.
- Since Python 3.6, mmap.write returns the number of bytes written.
- Since Python 3.3, mmap.read allows None as the parameter; while in
  Python 2 the argument cannot be omitted.

* Further clean up mmap.pyi

Use the fact that Python 3.0-3.4 are no longer supported to clean up the
version-dependent logic. Functions that always have different signatures
in Python 2/3 are moved from the base _mmap[bytes] to the mmap subclass.
2020-06-21 13:37:19 -07:00
Milap Sheth
671d6eb804 Update operator stubs to support slices for getitem/setitem/delitem (#4250) 2020-06-20 16:41:46 -07:00
Nipunn Koorapati
ca5cb9d006 Restore the global SSL flags to typeshed (#4247)
Audited this - and ensured the globals were gated under
the appropriate python versions for the boolean vars.
https://docs.python.org/3/library/ssl.html

Fixes #4246
2020-06-19 17:41:28 -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
Luciano Ramalho
1350e710cc max, min overloads with Protocol: fix #4051 (#4227) 2020-06-19 12:37:43 +02:00
Vlad Emelianov
d21370965a Allow Warning message in showwarning and formatwarning (#4239) 2020-06-17 17:44:09 -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
f67ea2031a xml.etree: use _typeshed (#4221) 2020-06-11 12:41:57 -07:00
Jelle Zijlstra
d0b85d7efe remove _types (#4220) 2020-06-11 09:10:52 +02:00
Shantanu
ecb43149f7 builtins: NotImplemented is not callable (#4222)
Fixes #3315

Co-authored-by: hauntsaninja <>
2020-06-10 22:05:16 -07: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
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
Phillip Huang
f4b23e4a80 Fix cgi.FieldStorage's __iter__ return type (#4209)
Co-authored-by: Phillip Huang <phillip@dropbox.com>
2020-06-08 20:40:14 -07:00
Shantanu
f2f65bcf8d profile/cProfile: minor improvements (#4202)
Co-authored-by: hauntsaninja <>
2020-06-08 11:45:55 +02:00
Shantanu
df6136c4ac logging: various fixes (#4196)
* logging.disable: update for py37

* RootLogger: fix __init__

* shutdown: add undocumented parameter

* MemoryHandler: add flushOnClose in py36

* NTEventLogHandler: fix dllname type

* makeSocket: add undocumented parameter

* SysLogHandler: fix socktype type

Co-authored-by: hauntsaninja <>
2020-06-07 14:05:29 -07:00
Jaromir Latal
4ab1d6f0ae [stdlib][logging] Make level default in logging.disable for 3.7+ (#4197) 2020-06-07 13:09:22 -07:00
Luciano Ramalho
bb9e1a649c using type var to work around List invariance (#4192) 2020-06-06 18:32:15 -07:00
Vegard Stikbakke
34b9cfcdcf curses.bkgset -> bkgdset (#4191) 2020-06-06 08:45:37 -07:00
karl ding
3f141751d7 cProfile: Fix Profile __init__ keyword arguments (#4183)
The CPython _lsprof module implementation uses the keyword arguments
'timer' and 'timeunit' instead of 'custom_timer' and 'time_unit' for
__init__. In profiler_init, the keyword argument parsing looks like the
following:

    static char *kwlist[] = {"timer", "timeunit",
                                   "subcalls", "builtins", 0};

This is the case ever since _lsprof was added in version 2.5.
2020-06-05 07:40:51 -07:00
Shantanu
db819480a5 logging: fix argument names (#4181)
* logging: fix argument names

* logging: filter method improvements

Co-authored-by: hauntsaninja <>
2020-06-04 19:32:03 -07:00
Shantanu
7aabfcc65a array: update for py39 (#4180) 2020-06-04 18:32:24 -07:00
Shantanu
5369e813a9 argparse: fix error __init__, add BooleanOptionalAction for py39 (#4144) 2020-06-04 16:00:52 -07:00
Sebastian Rittau
1f82564ee2 Move wsgiref.types to _typeshed.wsgi (#4175)
Re-export the types from wsgiref.types for now to avoid breaking
existing code. wsgiref.types should be removed eventually.

Also, reduce the boilerplate description in _typeshed/wsgi.pyi as it
mirrors the description in _typeshed/__init__.pyi.
2020-06-04 15:38:45 -07:00
Sebastian Rittau
eea9be6e73 Add a _typeshed.pyi file and a PathLike alias (#4161) 2020-06-04 14:06:43 +02:00
Sam Bull
bd35cd6bf8 Fixes for ssl (#4164) 2020-06-03 21:42:31 +02:00
Sam Bull
dd5ef5ed1e Add hostname_checks_common_name attribute to SSLContext (#4160) 2020-06-03 11:19:02 +02:00
Sebastian Rittau
a913af9523 flake8: Enable F811 (#4158) 2020-06-02 14:08:54 -07:00
karl ding
43cf0ec870 ssl: Improve SSLContext.options stub (#4152)
In Python 3.6, the SSLContext.options flags were converted from int to
EnumFlag values.

In addition, add the missing OP_ENABLE_MIDDLEBOX_COMPAT constant
introduced in version 3.6.

In addition, add the missing OP_NO_RENEGOTIATION constant introduced in
version 3.7.
2020-06-02 09:19:18 +02:00
karl ding
2137026681 socket: Add missing CAN_BCM option flag constants (#4151)
The SocketCAN BCM option flag constants were added in version 3.9,
and only backported to version 3.8, despite the documentation's claims
of supporting all BCM-related constants starting from version 3.4.

Note: The CAN_FD_FRAME flag option was only introduced in the 4.8.x
kernel series, while the rest of the constants were available since the
Broadcast Manager was mainlined in the kernel as part of the SocketCAN
patches.
2020-06-01 01:21:54 +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
Markus Pielmeier
b7d9a4a584 Add support for __pow__ with pow() builtin (#4109) 2020-05-30 15:38:19 -07:00
Shantanu
de2c2947fe windows: fix splitunc param name (#4143)
Co-authored-by: hauntsaninja <>
2020-05-29 20:37:19 -04:00
karl ding
09821cd9ca Add typing for CAN_J1939 sockets (#4141)
Add typing for CAN_J1939 sockets implementing support for the SAE J1939
protocol. This is available in Python 3.9+ on Linux 5.4+.
2020-05-29 12:33:47 +02:00
Rune Tynan
a1953431ff Move oem_(decode, encode) to be 3.6+ (#4140) 2020-05-28 18:57:32 -07:00