Commit Graph

4424 Commits

Author SHA1 Message Date
Jelle Zijlstra
d77d848975 contextlib: Use bound TypeVar (#7764) 2022-05-02 08:57:21 +02:00
Jelle Zijlstra
9effb643b3 logging.LoggerAdapter: Use a bound TypeVar (#7763) 2022-05-02 08:56:32 +02:00
Jim Crist-Harif
23e77931f9 Fix fields arg type in dataclass.make_dataclass (#7761)
The `fields` arg of `dataclass.make_dataclass` should have type:

```
Iterable[str | tuple[str, type] | tuple[str, type, Any]]
```

Previously the 3-tuple had type `tuple[str, type, Field[Any]]`, which
was incorrect for two reasons:

- The third element in the tuple doesn't have to be a ``Field``, it can
be any RHS value valid when defining a dataclass field (e.g.
``myfield: type = ...``). This may be a ``Field``, but it may also be a
default value like ``0``. ``Any`` is the proper type here.
- The type stubs for ``dataclass.field`` lie and say that this function
returns a value with the same type as ``default``. This avoids the need
for a mypy/pyright plugin that understands dataclasses, but also means
there is no way to create a ``Field`` object that these tools
understand, since they don't think ``dataclasses.field`` returns a
``Field`` instance.

With this change, the following valid dataclasses code passes both mypy
and pyright:

```python
from dataclasses import field, make_dataclass

Point = make_dataclass("Point", [("x", int), ("y", int), ("z", int, 0)])
Point2 = make_dataclass("Point2", [("x", int), ("y", int), ("z", int, field(default=0))])
```
2022-04-30 23:02:40 -06:00
fedor
e8e74ba26f Use object for value annotation in Enum.__new__ (#7752)
This pull request reverts part of #2539 that brought back a bug discussed in https://github.com/python/mypy/issues/5788 and initially fixed in #2539

In short, the issue was that the following program always resulted
in an error when running mypy with the `--disallow-any-expr` flag:

    from enum import Enum

    class MyEnum(Enum):
        FOO = 1
        BAR = 2

    blah = MyEnum   # Error here

The root issue was that because the signature of Enum's
`__new__` method was typed as:

    def __new__(self: Type[T], value: Any) -> T: ...

This caused mypy to decide that the type of `MyEnum` was
`(Any) -> MyEnum`. This is correct based on the current
type signature, but unfortunately means that it becomes
impossible to ever use enums with the `--disallow-any-expr` flag.
2022-04-30 12:36:35 -06:00
Jelle Zijlstra
7e7562b95b Add socket.TCP_CONNECTION_INFO (#7755)
python/cpython#69256
2022-04-30 09:24:09 -06:00
Jelle Zijlstra
e6623754e9 sqlite: Blob now uses ints in getitem/setitem (#7754)
I just merged python/cpython#92020 which implemented this change (thanks @erlend-aasland!).
2022-04-30 09:15:03 -06:00
Akuli
7d046654f1 Accept lists of tuples in tkinter.Canvas.create_foo() methods (#7722)
Fixes #7698.

At runtime, these methods call `tkinter._flatten()`, which recursively turns lists or tuples (but not other sequences) into a flat tuple of items. Unfortunately we don't have recursive types yet.
2022-04-30 06:52:56 -06:00
Jelle Zijlstra
145e659482 inspect: Add positions attributes that will be new in 3.11 (#7688) 2022-04-29 17:00:37 -06:00
Akuli
205959917b sys: delete unnecessary python version check (#7742) 2022-04-29 22:58:36 +02:00
Alex Waygood
c3ebc7e307 More improvements to pow stubs (#7737) 2022-04-28 10:49:29 -06:00
Sebastian Rittau
5df8de7693 Move a few protocol from builtins to _typeshed (#7736) 2022-04-28 17:36:47 +02:00
Akuli
bfa918880f asyncio: expose WriteTransport.get_write_buffer_limits on all Python versions (#7718) 2022-04-27 16:38:25 +03:00
Akuli
7576c5e1d5 asyncio: add missing methods to _FlowControlMixin (#7719) 2022-04-27 16:32:22 +03:00
Jelle Zijlstra
2299c43860 decimal: kwargs to localcontext() (#7686) 2022-04-26 13:19:29 +02:00
Prometheus3375
e833b5a095 Fix typing for XMLPullParser.feed() (#7695)
Closes #7681
2022-04-26 11:09:25 +02:00
Jelle Zijlstra
2668cae090 Add PickleBuffer to _typeshed.WriteableBuffer (#7683)
Fixes #4362
2022-04-26 09:14:37 +02:00
Alex Waygood
7cbb579a44 Make __wrapped__ read-only on classmethods and staticmethods (#7694) 2022-04-25 22:27:06 -06:00
Jelle Zijlstra
573539ba2a multiprocessing: add shutdown_timeout param to BaseManager (#7692)
python/cpython#32112
2022-04-25 22:12:56 -06:00
Jelle Zijlstra
85a6f0ffe9 socket: add all_errors param to create_connection (#7691)
python/cpython#91704
2022-04-25 22:10:29 -06:00
Jelle Zijlstra
c8a978f756 typing: Add dataclass_transform (#7690)
python/cpython#91861
2022-04-25 22:06:32 -06:00
Jelle Zijlstra
ac2b24c08f warnings: New arguments to catch_warnings() in 3.11 (#7685) 2022-04-25 21:19:29 -06:00
Jelle Zijlstra
125f9b4275 sqlite3: Add sequence methods to Blob (#7684)
python/cppython#91599
2022-04-25 20:17:09 -07:00
Jelle Zijlstra
08ae9f324b subprocess: Add _USE_VFORK and _USE_POSIX_SPAWN (#7687)
These are now documented: python/cpython#91490
2022-04-25 21:13:39 -06:00
Jelle Zijlstra
02e0c98d62 Buffer support for re (#7679) 2022-04-23 18:28:35 -07:00
Jelle Zijlstra
5dad506bf2 binascii: Improve bytes types (#7677)
Add missing arguments to b2a_hex()
2022-04-23 20:57:02 +02:00
Jelle Zijlstra
00f4031915 pickle: accept ReadableBuffer (#7678) 2022-04-23 20:54:20 +02:00
Jelle Zijlstra
66383ee8e3 unittest.mock: target must be a str (#7672)
See [the CPython source](eaa85cb22f/Lib/unittest/mock.py (L1754)). It calls `_get_target`, and [that](eaa85cb22f/Lib/unittest/mock.py (L1594)) does `target.rsplit('.', 1)`.
2022-04-21 14:07:55 -07:00
Alex Waygood
a8504f269e Use _typeshed.OptExcInfo in pydoc and unittest (#7668) 2022-04-20 21:00:48 +01:00
Alex Waygood
b093c90a94 Use TypeAlias for type aliases where possible, part II (#7667) 2022-04-20 20:02:47 +01:00
Alex Waygood
c653be73b8 Use TypeAlias for argparse type aliases (#7664) 2022-04-20 07:32:10 -07:00
Alex Waygood
85594df83b Use re-exports instead of TypeAliases in email.parser (#7665) 2022-04-20 07:31:52 -07:00
Alex Waygood
3930d8d12a Make several type aliases private (#7661) 2022-04-18 22:19:16 +01:00
Shantanu
67425a89d4 hashlib: update for py311 (#7652)
Co-authored-by: Akuli <akuviljanen17@gmail.com>
2022-04-18 21:21:19 +03:00
Alex Waygood
617d2aaf57 Fix crash when running mypy master against typeshed master (#7660) 2022-04-18 17:20:49 +01:00
Alex Waygood
eafc23ddb8 Add one more # noqa to unblock https://github.com/PyCQA/flake8-pyi/pull/213 (#7659)
Missed one.
2022-04-18 09:09:40 -07:00
Alex Waygood
54af68c789 Add a few # noqas to unblock PyCQA/flake8-pyi#213 (#7658) 2022-04-18 17:57:48 +02:00
Alex Waygood
073f9f416d Use PEP 585 syntax in collections (#7657) 2022-04-18 15:33:50 +01:00
Alex Waygood
97a74bc1aa Import from collections.abc wherever possible (#7635) 2022-04-18 12:50:37 +02:00
Sebastian Rittau
321359ca31 Add _typeshed.(Opt)ExcInfo (#7645) 2022-04-18 00:28:43 +01:00
Jelle Zijlstra
a24b765388 improve type for itertools.zip_longest (#7655) 2022-04-17 15:49:05 -07:00
Shantanu
a24ce3f935 dis: update for py311 (#7649) 2022-04-17 20:40:39 +03:00
Shantanu
b562089d13 ast: add TryStar in py311 (#7646)
Co-authored-by: hauntsaninja <>
2022-04-16 22:13:21 -07:00
Shantanu
556fe3e4ef weakref: use positional-only args (#7653)
Co-authored-by: hauntsaninja <>
2022-04-16 22:10:39 -07:00
Shantanu
435f758019 sqlite3: add py311 constants (#7654)
bpo-24139
2022-04-16 22:08:42 -07:00
Alex Waygood
7ce4607dee Upgrade flake8-pyi to 22.4.0, enable Y026 in .flake8 config (#7650) 2022-04-17 01:23:35 +01:00
Shantanu
145a85307a random: update for py311 (#7651) 2022-04-17 01:01:36 +01:00
Shantanu
520f807b5f builtins: default values for int.(to|from)_bytes in py311 (#7647)
See https://github.com/python/cpython/issues/89318
2022-04-17 00:57:13 +01:00
Shantanu
c93f92d92e builtins: add BaseExceptionGroup.__class_getitem__ (#7648) 2022-04-17 00:48:46 +01:00
Jelle Zijlstra
bedf520d76 typing(_extensions) updates for 3.11 (#7643) 2022-04-16 21:42:12 +02:00
Sebastian Rittau
499e74cf2a Add wsgiref.types (Python 3.11+) (#7644)
_typeshed.wsgi: Import from wsgiref.types in Python 3.11+

Make types match wsgiref.types
2022-04-16 21:36:31 +02:00