Commit Graph

900 Commits

Author SHA1 Message Date
Akuli
c065982b7a support anything with .keys() and __getitem__ in dict.__init__ (#4470) 2020-08-24 13:03:38 +02:00
Guido van Rossum
351a971b1d Add token.EXACT_TOKEN_TYPES for 3.8+ 2020-08-23 15:42:01 -07:00
Mario Ishac
4bbe161479 Made methodcaller's name argument positional (#4476) 2020-08-22 15:13:02 -07:00
Shantanu
f23ce60668 stubtest: fix on windows (#4455)
Co-authored-by: Akuli
2020-08-17 14:55:58 -07:00
Shantanu
b438ccc3bc PathLike: change to Protocol (#4447)
Co-authored-by: hauntsaninja <>
2020-08-16 05:15:51 -07:00
Eric Traut
002a444dff Added missing type annotations for fractions and numbers modules. (#4401)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2020-08-15 18:28:14 -07:00
Selim Belhaouane
8059ea72f8 Fix type for path in ZipFile.extract (#4445) 2020-08-14 15:15:43 -07:00
Christopher Schramm
fddc78293a Extend function pointer type returned by CDLL (#4444)
CDLL.__getattr__ and __getitem__ return function pointers that have a __name__ attribute set, so "CDLL(lib).fun.__name__" is valid code but currently not covered.
2020-08-13 17:35:36 +02:00
Jukka Lehtosalo
866b0c3bf0 ConfigParser: accept readline() that takes no arguments (#4433)
At runtime readline() is called without arguments, so requiring
an optional argument may result in false positives.
2020-08-10 15:55:32 +01:00
Eric Traut
baaffed1ac Added missing type annotations in various stdlib stubs. (#4402)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2020-08-06 18:27:21 -07:00
Andreas Poehlmann
10a5b070ab Fix contextlib.ContextDecorator.__call__ types (#4399)
The decorated function returned by ContextDecorator.__call__ has
the same call signature as the original function.

Closes #4382.
2020-08-06 17:26:54 -07:00
Eric Traut
f60074f3d2 Fixed symbol redefinition in cgi.pyi stub (#4394)
* PEP 484 says that type checkers should assume that all types used in a stub should use forward declarations even though they are not quoted. This stub is using the symbol "type" within the context of a class scope. The "type" symbol is declared within this scope, so pyright assumes that the forward declaration should be used. The solution is to define a symbol with a different name in the outer scope to avoid the name conflict.

* Fixed import sort order.

Co-authored-by: Eric Traut <erictr@microsoft.com>
2020-08-06 09:05:45 +02:00
Eric Traut
65450d81ff Fix multi-part module import errors (#4395)
* Pyright detects and reports cases where a multi-part module name is accessed but is not explicitly imported. These are dangerous because they rely on import resolution ordering within a program, which can easily change. This change eliminates errors detected by pyright.

* Fixed regression caught by CI test.

* Fixed black formatting issues.

Co-authored-by: Eric Traut <erictr@microsoft.com>
2020-08-06 09:03:54 +02:00
Eric Traut
04c74640f0 Removed imported symbols that are not accessed or re-exported (#4387)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2020-08-05 22:49:17 -07:00
frehoy
7894269bb5 Proposed fix for tarfile.add() accepting Path name and arcname (#4369)
Co-authored-by: Akuli <akuviljanen17@gmail.com>
2020-07-31 16:55:45 +02:00
karl ding
8f50cd9d0e Add missing syslog facility codes (#4366)
Add support for the following syslog facilities:

  - LOG_NTP
  - LOG_SECURITY
  - LOG_CONSOLE
  - LOG_SOLCRON

In addition, reorder the entries to match the CPython implementation to
make it easier to read.
2020-07-27 12:34:12 +02:00
Vegard Stikbakke
51fd8b2a06 Fix Filter.filter return type - bool, not int (#4358) 2020-07-24 20:25:06 +02:00
Peter Law
29dec525e7 Add pydoc_data (#4351)
This appears to be used by jedi at least, so it would be great to
have stubs for it.
2020-07-21 18:14:03 -07:00
Philipp Hahn
e44ac21d98 optparse: option_class is Type[Option] (#4338)
It's a `class`, not an `instance`.

<https://docs.python.org/2.7/library/optparse.html#optparse.OptionParser>
2020-07-17 20:50:02 +02:00
Sebastian Rittau
5e76f51930 Upgrade to isort 5 (#4323)
This now also reformats imports not at the top of files.
2020-07-16 07:01:57 -07:00
Shantanu
5ecdc08bb1 tarfile: fix arg name (#4326)
And update whitelist since #4322 fixed a thing

Co-authored-by: hauntsaninja <>
2020-07-12 20:27:43 +02:00
Sebastian Rittau
9ad8ed3b75 Introduce Mapping-like protocols (#4325)
typing.Mapping is not a protocol, which has caused problems in the past.
(E.g. python/typeshed#3569, see also python/typeshed#3576.) This
introduces a few narrow protocols to _typeshed.pyi that can be used in
place of Mapping.

Not all uses of Mapping can be replaced. For example, cgi.FieldStorage
explictly checks whether the supplied headers argument is a Mapping
instance.
2020-07-11 17:11:08 -07:00
Jonathan Slenders
028f0d5293 Fix: TarFile.tarinfo is a Type instead of instance. (#4322)
Co-authored-by: Jonathan Slenders <jslender@cisco.com>
2020-07-10 12:22:04 +02:00
Alex Grönholm
ad89dee03b Fixed return type of getaddrinfo() everywhere (#4304) 2020-07-10 10:46:28 +02:00
Joshua Oreman
e6736cde8d ctypes: allow cast() 1st argument to be int and 2nd argument to be Type[py_object] (#4311) 2020-07-10 10:44:23 +02:00
Alex Grönholm
f9d469ac2b Fixed parameter and return types of getnameinfo() everywhere (#4305) 2020-07-03 15:46:02 +02:00
wouter bolsterlee
83e955b52f Use correct return type annotation for BaseException.with_traceback (#4298)
The return type of the BaseException.with_traceback() method [1] is not
specific enough. The return type is guaranteed to be of the same type as
‘self’, which is usually a subclass of BaseException.

In fact, .with_traceback() returns ‘self’:

    try:
        raise ValueError
    except Exception as exc:
        assert exc.with_traceback(None) is exc

Fix the annotation to reflect this using the self-type annotation
technique described in PEP484 [2], which is supported by (at least)
mypy [3].

[1] https://docs.python.org/3/library/exceptions.html#BaseException.with_traceback
[2] https://www.python.org/dev/peps/pep-0484/#annotating-instance-and-class-methods
[3] https://github.com/python/mypy/issues/1212
2020-06-30 11:40:25 -07:00
Artem Simonov
f0269cd438 fix shutil.chown type annotations (#4294)
According to the official docs, "user can be a system user name or a uid;
the same applies to group".

Co-authored-by: Artem Simonov <artem.simonov@dejero.com>
2020-06-30 09:39:38 +02:00
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
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