Commit Graph
100 Commits
Author SHA1 Message Date
Jelle Zijlstra 5f591a1a12 fix VERSIONS (#5329) 2021-05-07 08:43:22 +02:00
Jelle Zijlstra 38dfb57adf Improve asyncio.subprocess stubs (#5327) 2021-05-02 21:50:29 -07:00
Jelle Zijlstra 2c8cb60596 Fix permissions for mypy-primer-comments (#5259)
Based on https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#permissions
2021-04-27 18:05:20 +02:00
Jelle Zijlstra cb108516f6 add cProfile.Profile.stats (#5246)
* add cProfile.Profile.stats

* also add to profile.pyi
2021-04-24 18:28:22 +03:00
Jelle ZijlstraandShantanu fc0db5f2b6 Add a suggestion to CONTRIBUTING.md (#5205)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
2021-04-11 06:50:08 -07:00
Jelle Zijlstra 97c6806582 Revert "Awaitable.__await__ should accept an Iterator rather than a Generator (#5194)" (#5195)
This reverts commit c687e297ec.
2021-04-09 09:49:39 +02:00
Jelle Zijlstra 30fc2b8cd0 fix positional-only arguments to str and bytes (#5112) 2021-03-12 15:33:25 -08:00
Jelle Zijlstra 3e9ed39bec remove "Union[str, str]" (#4838)
I grepped and didn't find any other instances of redundant unions like this one.
2020-12-18 14:13:41 -06:00
Jelle Zijlstra 301325b55b Make _GeneratorContextManager covariant (#4733)
Fixes  #4732
2020-10-30 17:31:55 -07:00
Jelle Zijlstra 5f9fd3d127 upgrade black version (#4486)
Manually removed a number of trailing commas to prevent black from unnecessarily
exploding some collections.
2020-08-26 18:36:01 +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
Jelle Zijlstra 5d553c9584 apply black and isort (#4287)
* apply black and isort

* move some type ignores
2020-06-28 13:31:00 -07:00
Jelle Zijlstra e1d89e5742 remove references to "Text" in Python 3-only stubs (#4251) 2020-06-22 12:39:01 +02:00
Jelle Zijlstra f67ea2031a xml.etree: use _typeshed (#4221) 2020-06-11 12:41:57 -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 ZijlstraandShantanu 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
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
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
Jelle Zijlstra c80622fbb9 remove type ignores about python/mypy#5027 (#4119)
The mypy issue got fixed by the good people of mypy. I did have to add an
override for __enter__ similar to what we're doing in #4082.
2020-05-28 09:51:54 -07:00
Jelle Zijlstra 0cffa59e57 use a Protocol for str.format_map() (#4122)
Fixes #3824
2020-05-28 13:27:57 +02:00
Jelle Zijlstra ca553cd589 fix type for ipaddress._BaseNetwork.overlaps (#4124) 2020-05-28 13:22:50 +02:00
Jelle ZijlstraandShantanu 4a9fdcc7fc uuid: update for py39 (#4023)
Closing the long loop started in #3715

Co-authored-by: Shantanu <hauntsaninja@users.noreply.github.com>
2020-05-16 21:30:45 -07:00
Jelle Zijlstra d55df54ae2 upgrade flake8 (#3980) 2020-05-13 08:52:40 +02:00
Jelle Zijlstra 23e380ac83 add overload to difflib.get_close_matches (#3908)
Fixes #3906. Fixes #2067.
2020-04-05 14:12:29 +02:00
Jelle Zijlstra e9a9103afc bring back attribute types in warnings.WarningMessage (#3810)
Signed-off-by: Oleg Höfling <oleg.hoefling@gmail.com>
2020-03-05 17:15:13 -08:00
Jelle Zijlstra 6a4044fd9b Make frozenset covariant (#3808)
The convariance was lost in #1057
2020-03-04 19:24:03 -08:00
Jelle Zijlstra 6b751ef408 shutil: Fix rmtree type (#3536)
See my comment in https://github.com/python/typeshed/issues/3533#issuecomment-563366251.
2019-12-21 12:29:59 -08:00
Jelle Zijlstra 5021b30711 functools: remove first type param of cached_property (#3553)
Fixes #3547

This removes some type safety in exceptional cases, like code that interacts
directly with cached_property objects, but that seems like a price worth
paying.
2019-12-21 10:42:43 -08:00
Jelle Zijlstra 97f830030c Simplify WatchedFileHandler.__init__ (#3506)
Fixes #3502
2019-12-03 14:54:29 +01:00
Jelle Zijlstra d215f502c6 Improve warnings stubs (#3501)
* merge 2and3 for _warnings

* move warn and warn_explicit into _warnings
2019-12-03 14:33:37 +01:00
Jelle Zijlstra 1f0dc6ee05 timeout argument to urllib.request.urlopen is Optional (#3487)
The docs (https://docs.python.org/3/library/urllib.request.html#urllib.request.urlopen) aren't very precise about this, but passing `None` seems to work in practice.
2019-11-24 12:51:33 +01:00
Jelle Zijlstra a89f883878 stream argument to pprint.pprint is Optional (#3488)
None is the default; see https://docs.python.org/3/library/pprint.html#pprint.PrettyPrinter
2019-11-24 12:29:43 +01:00
Jelle Zijlstra cd5cd12a35 asyncio: fix windows stubs (#3424) 2019-10-30 08:13:32 -07:00
Jelle Zijlstra c38cf6736e Allow callables in _SourceObjectType (#3295)
This is important because mypy doesn't generally think functions are compatible with `FunctionType`, so `inspect.getsource` on arbitrary functions is rejected by the current annotations.
2019-10-03 00:52:21 +02:00
Jelle Zijlstra d05a9d3d83 Improve enums (#3168)
I realized while working on srittau/type-stub-pep#64 that a
few things we do in existing enum definitions in typeshed are
problematic:

- Using "= ..." doesn't allow type checkers to correctly type the
  result of Enum.MEMBER.value. In fact, mypy at least infers
  .value to be "Ellipsis" if you do this.
- Properties on the enum values themselves, like HTTPStatus.phrase,
  should not be specified directly as attributes, because it makes
  type checkers think that the properties themselves are enum
  members.

I ended up doing a bit more cleanup to the signal module:
- Remove unnecessary ... initializers.
- Remove unnecessary _SIG = Signals alias.
- I don't have Windows to test, but the C code for _signal suggests
  that CTRL_C_EVENT and CTRL_BREAK events are not Signals, but just ints:
  https://github.com/python/cpython/blob/1dbd084f1f68d7293718b663df675cfbd0c65712/Modules/signalmodule.c#L1575
2019-08-05 08:08:57 -07:00
Jelle Zijlstra b0c9fa4530 fix type of loop.sock_connect (#3073) 2019-06-21 17:31:51 +02:00
Jelle Zijlstra ada0570efc Revert "Define functools.partial as overloaded function instead of its own class (#2878)" (#3077)
This reverts commit e45f443d85.
2019-06-20 20:39:49 -07:00
Jelle Zijlstra cd9b7158ec fix CI (#2992) 2019-05-15 14:20:08 -07:00
Jelle Zijlstra b5493e8639 add types.FunctionType.__init__ (#2968)
Fixes #2930
2019-05-07 17:31:01 +02:00
Jelle Zijlstra d7e9af4492 allow callables in dis() (#2969)
Fixes #2914
2019-05-07 17:21:54 +02:00
Jelle Zijlstra bdb1de57f5 narrow signature of __contains__ for str-like classes (#2967)
Fixes #2937
2019-05-07 10:24:28 -04:00
Jelle Zijlstra 8bd744a38f fix type of msg argument to HTTPRedirectHandler.redirect_request (#2949)
It's not really documented (https://docs.python.org/3/library/urllib.request.html#urllib.request.HTTPRedirectHandler.redirect_request), but logically a message is a str, and reading the code for the stdlib confirms that it's intended to be a str.
2019-05-03 20:44:56 +02:00
Jelle Zijlstra ff650d3275 socket: add .set_inheritable() (#2935) 2019-04-28 17:13:20 +02:00
Jelle Zijlstra ce2b8a838c reword "What to include" (#2861) 2019-04-08 19:02:01 +02:00
Jelle Zijlstra 832bf52c28 asyncio: make type alias private and CamelCase (#2849) 2019-03-11 08:43:00 +01:00
Jelle Zijlstra 14e387b6fd fix some minor lint errors (#2820)
Caught by a newer version of flake8
2019-03-01 12:29:23 +01:00
Jelle Zijlstra b5897d5643 fix undefined name in flask stub (#2811) 2019-02-23 10:28:03 +01:00
Jelle Zijlstra 2aee28cb6f fix missing space in imghdr (#2812) 2019-02-23 10:26:51 +01:00
Jelle Zijlstra 78690405cf add back StopIteration.value in Python 3 (#2744)
Fixes python/mypy#6209.
2019-01-16 19:21:16 -08:00
Jelle Zijlstra 46ab77eb20 loop argument to asyncio.ensure_future is Optional (#2708)
The default value is None: https://github.com/python/cpython/blob/master/Lib/asyncio/tasks.py#L616.
2018-12-20 15:24:03 -08:00
Jelle Zijlstra 1a42a2c3ea fix list concatenation (#2404)
Fixes #2383, python/mypy#5492.
2018-11-08 06:42:57 -08:00
Jelle Zijlstra 63cf7f529b fix lint error (#2541) 2018-10-23 14:00:26 +02:00
Jelle Zijlstra bc3f9fe1d3 fix typing.Pattern in Python 2 (#2219)
Fixes #2199
2018-10-01 20:35:13 -07:00
Jelle Zijlstra 1bc1fc2117 add constructor arguments for TimeoutExpired (#2466)
Previously, constructing a TimeoutExpired directly worked because Exception allowed arbitrary kwargs. We fixed that recently, but now mypy gives an error on creating a TimeoutExpired with legal arguments.
2018-09-18 14:02:38 +02:00
Jelle Zijlstra 8b9e4c378a fix module argument to unittest.main (#2403) 2018-09-10 11:04:05 -07:00
Jelle Zijlstra 9d62d6d5c5 fix __metaclass_ references (#2402) 2018-09-06 18:24:03 -07:00
Jelle Zijlstra 2e1c81684e fix duplicate definitions in tornado (#2424)
Fixes #2423.

I followed https://github.com/tornadoweb/tornado/blob/master/tornado/httpclient.py and kept the `@property` where it exists in the implementation and the attribute where it doesn't.
2018-09-03 16:39:51 -07:00
Jelle Zijlstra 6f62466d6f fix selftest (#2425)
Now that the typeshed submodule has moved.
2018-09-03 10:35:20 -07:00
Jelle Zijlstra 761b620e1a add @srittau to maintainers (#2420) 2018-08-28 16:50:50 +02:00
Jelle Zijlstra 9e023e7586 minor namedtuple fixes (#2227)
- The extra arguments aren't keyword-only in 2.7.
- Added the `defaults` argument in 3.7 (https://docs.python.org/3.7/library/collections.html#collections.namedtuple).
2018-08-19 03:47:10 +01:00
Jelle Zijlstra fd6f99ca2c fix mypy-selftest (#2341) 2018-07-18 21:12:37 -07:00
Jelle Zijlstra 574807d9ea os.get_terminal_size also exists on Windows (#2338)
... at least according to https://docs.python.org/3/library/os.html#os.get_terminal_size.

Related to python/mypy#5370.
2018-07-18 10:25:12 -07:00
Jelle Zijlstra 7d3ec1e0be Improvements to pymysql (#2220)
* don't use type comments

* split up long lines

* all the constants are ints

* fixes to pymysql stub

* drop __all__, fix tabs
2018-07-13 19:43:09 -07:00
Jelle Zijlstra fc290167eb Fixes to boto.s3.key stub (#2317)
* replace type comments in key.pyi

* reformat the file with black

* get_contents_as_string returns bytes unless an encoding is specified

http://boto.cloudhackers.com/en/latest/ref/s3.html#boto.s3.key.Key.get_contents_as_string
2018-07-13 19:39:24 -07:00
Jelle Zijlstra 00cda79cf5 add io.TextIOWrapper.read in 3.3 (#2248)
This is needed to make TextIOWrapper and a few classes that inherit
from it concrete in 3.3. I am actually not sure whether this method
exists at runtime; there's nothing in
https://docs.python.org/3/library/io.html#io.TextIOWrapper
that suggests it was added in 3.4. In any case, it hardly matters
since 3.3 usage should be very rare now.
2018-06-17 23:47:07 +01:00
Jelle Zijlstra 3032fbdff1 make http.client.HTTPResponse concrete in 3.4 (#2244)
Matches the implementation in https://github.com/python/cpython/blob/3.4/Lib/http/client.py#L308

The ignore works around python/mypy#5027 (commented further up in the 3.5 branch).

Part of #1476.
2018-06-17 17:29:02 +01:00
Jelle Zijlstra da8de48f6d UserList and UserString in 2.7 (#2246)
Fill out UserList and UserString stubs to make the classes concrete. Compare:
https://github.com/python/cpython/blob/2.7/Lib/UserList.py
https://github.com/python/cpython/blob/2.7/Lib/UserString.py
2018-06-17 17:24:30 +01:00
Jelle Zijlstra 8084dc1c1f Fix abstract classes in 2.7 (#2247)
Part of #1476.
2018-06-17 17:21:17 +01:00
Jelle Zijlstra 6b36b1befe Iterator provides a concrete __iter__ in 2.7 (#2245)
This is already how it works in the Python 3 stub.

`Iterator.__iter__` also exists at runtime: https://github.com/python/cpython/blob/2.7/Lib/_abcoll.py#L73.
2018-06-17 12:00:42 +01:00
Jelle Zijlstra 0393de4bd7 fix some abstract classes in Python 2 (#2240)
Part of #1476.
2018-06-17 00:56:00 +01:00
Jelle Zijlstra 94ab32ba59 Fix abstract classes for Python 3 (#2239)
* add metaclass=ABCMeta to some classes

* mark some more classes as explicitly abstract

* make some more classes concrete
2018-06-16 10:18:54 -07:00
Jelle Zijlstra 341fa375ef cleanup in typing.pyi (#2241)
- Fix TODOs around TracebackType
- Don't use quotes for forward references
- Make Generator and AsyncGenerator attributes into properties
2018-06-16 08:24:52 -07:00
Jelle Zijlstra c06a718c5b always run mypy with --no-implicit-optional (#2242)
This was already the configuration in Travis and it's been working fine. It's
confusing that Travis was using a different configuration than the default
when you run tests/mypy_test.py yourself.
2018-06-15 21:34:14 -07:00
Jelle Zijlstra 499f852e37 add --show-traceback to mypy_test.py flags (#2236)
This makes debugging easier.
2018-06-15 16:46:59 -07:00
Jelle Zijlstra de86f15fa0 Make http.client.HTTPResponse a BinaryIO (#2218)
Fixes #2189.

The errors from mypy are a false positive (see python/mypy#5027).
2018-06-12 09:20:24 -07:00
Jelle Zijlstra 6bbf3d89eb Further improve codecs stubs (#2217)
- remove header comments
- uppercase type aliases
- remove old-style type annotations
- unquote forward refs
- reformat the file
- remove values for globals
- don't use private names from codecs stub in io.pyi
2018-06-11 22:24:34 -07:00
Jelle Zijlstra bdb06b5b81 improve codecs stubs (#2114)
Started out as progress towards #1476, but I ended up fixing a few more things:
- fixed the signature of _encode_type, which actually returns a pair, not a string
- made some attributes into properties in order to prevent the descriptor protocol from turning them into methods
- found a bug in CPython in the process (python/cpython#6779)

I used the following test file to make sure these classes are now instantiable:

```python
import codecs
import io
from typing import IO

bio = io.BytesIO()
cod = codecs.lookup('utf-8')

codecs.StreamReaderWriter(bio, codecs.StreamReader, codecs.StreamWriter)
codecs.StreamRecoder(bio, cod.encode, cod.decode, codecs.StreamReader, codecs.StreamWriter)
```
2018-06-11 15:53:15 -07:00
Jelle Zijlstra d2469c0e89 fix type for itertools.product (#2129)
Fixes #1850.

The fix was already applied to Python 2, but the typevar-based solution there
leads to "cannot infer value of type variable" in mypy. I used the following
script to check:

```python
from itertools import product

reveal_type(product([1]))
reveal_type(product([1], ['x'], [False], [3.0], [(1,)], [('x',)], [{1}], [{1: 2}], repeat=5))
```
2018-06-11 15:52:44 -07:00
Jelle Zijlstra ced5d61bb6 make urllib.response.addinfourl instantiable (#2134)
Fixes #1377 (because HTTPError is a subclass of addinfourl). Also part of #1476.
2018-06-11 15:43:53 -07:00
Jelle Zijlstra 4e6af84640 improve multiprocessing.Pool types (#2126)
Fixes #1703

Mostly introduce typevars to express that the return types match the return types of the
callbacks.

Removed comment about incompleteness since all documented classes from
https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing.pool
are covered.
2018-06-11 14:42:57 -07:00
Jelle Zijlstra 82c930e66c Improve asyncio.tasks stubs (#2139)
- Use PEP 526-style variable annotations where possible
- Use FrameType instead of Any
- Remove workaround for mypy issue that was since fixed
2018-06-11 14:40:54 -07:00
Jelle Zijlstra f5a74fd5da remove Optional from type of __slots__ (#2128)
Fixes #1853
2018-06-11 14:29:11 -07:00
Jelle Zijlstra f65caed181 allow socket.recv_into to take a memoryview (#2127)
Fixes #1862
2018-06-11 14:25:11 -07:00
Jelle Zijlstra cb293ebd2e switch order of base classes on awaitable classes (#2125)
Fixes #1940.

This makes it so that mypy will infer the common base class of these
classes to be Awaitable instead of Iterable. I verified that this
fixes the errors in the script posted by @neilconway.
2018-06-11 14:20:31 -07:00
Jelle Zijlstra 7abcd0f71f add ConfigParser.readfp in Python 3 (#2123)
https://docs.python.org/3/library/configparser.html#configparser.ConfigParser.readfp

Fixes #2112
2018-06-11 14:10:52 -07:00
Jelle Zijlstra 53fde2ddf7 make timeout argument to Connection.poll Optional (#2122)
Fixes #2094
2018-06-11 14:04:45 -07:00
Jelle Zijlstra 91af6291b1 make shlex.shlex and multiprocessing.pool.IMapIterator instantiable (#2120)
Part of #1476.
2018-06-11 14:04:05 -07:00
Jelle Zijlstra c5bc3bd7fa make contextvars.Context instantiable (#2119)
Part of #1476.
2018-06-11 14:03:02 -07:00
Jelle Zijlstra f789ee25ad make EnumMeta instantiable (#2118)
part of #1476. Verified that len(Enum) is still allowed by mypy.
2018-06-11 14:02:16 -07:00
Jelle Zijlstra f73351f5bf make tracemalloc.Traceback instantiable (#2117) 2018-06-11 14:01:46 -07:00
Jelle Zijlstra 28f6c095d4 make http.cookies.{Base,Simple}Cookie instantiable (#2116)
Part of #1476.
2018-06-11 14:01:17 -07:00
Jelle Zijlstra a33a124537 make BZ2File and LZMAFile instantiable (#2115)
Part of #1476.
2018-06-11 13:59:38 -07:00
Jelle Zijlstra 764ee4eeec add pytz.ZERO and pytz.HOUR (#2180)
https://github.com/stub42/pytz/blob/master/src/pytz/__init__.py#L187
2018-06-11 11:27:34 -07:00
Jelle Zijlstra 38fb53eab6 add __init__ to SimpleNamespace (#2207)
```In [11]: SimpleNamespace(x=3)
Out[11]: namespace(x=3)
```
2018-06-11 08:08:41 -07:00
Jelle Zijlstra cd4a5ff65c use pytype-single rather than pytype (#2198)
Looks like this happened in https://github.com/google/pytype/commit/3de774361b2481b55ef493391429e88571f7b9f2.
2018-06-05 08:34:21 -07:00
Jelle Zijlstra eef0b1d562 fix type for TestCase.assertIn (#2186)
* fix type for TestCase.assertIn

This does essentially `assert member in container`, so we want a `Container`, not an `Iterable`.

This came up in https://github.com/ambv/black/pull/288/files/68e9d426a86edc187a3f58ea889a2002620f0de6..0bbee43d60dfc16d8bbdd0bbdaad754a2c8c7ec0#r192525658.

* use any for assertIn
2018-06-04 15:34:09 -07:00