Commit Graph

179 Commits

Author SHA1 Message Date
Akuli 3c90c97b9a List[Foo] + List[Bar] now returns List[Foo | Bar] (#8293)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-07-15 20:20:50 +03:00
Alex Waygood 9645dae925 int.denominator, int.imag: More precise return types (#8266) 2022-07-14 11:25:05 +01:00
Jelle Zijlstra 2a7439e106 Revert "add overload to tuple.__new__ to better express an empty tuple" (#8278)
This reverts commit 64554bdd5d.

Also add a test case.
2022-07-12 12:29:37 -07:00
Sebastian Rittau faae950ade Use error codes for type ignores (#8280)
Disable reportSelfClsParameterName for pytype as this is out of typeshed's
control

Closes: #7497
2022-07-12 20:15:49 +02:00
Alex Waygood edc0ecd857 Remove Python 3.6 branches from typeshed (#8269) 2022-07-11 10:55:17 +02:00
David Brownman 64554bdd5d add overload to tuple.__new__ to better express an empty tuple (#7454)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2022-07-05 17:28:08 -07:00
Alex Waygood e19073e871 Add a tiny bit more special-casing for sum (#8231) 2022-07-02 20:05:56 +01:00
Alex Waygood 1828ba2045 builtins.sum: Items in the iterable must support addition with int if no start value is given (#8000) 2022-06-13 11:25:38 +01:00
Jim Bosch a2ba0c8a00 use __new__ instead of __init__ for frozenset (#8019) 2022-06-04 08:31:13 -07:00
Graham Bleaney 8c434e05d6 Add PEP 675 LiteralString overloads to str class (#7725)
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2022-05-31 21:09:34 -07:00
pranavrajpal 8f33ff9e9d Add __setstate__ for BaseException (#7987) 2022-05-30 11:33:55 +02:00
Alex Waygood d4eba8b5ce builtins.sum: Add overload for bool special case (#7975)
Closes #7974
2022-05-28 11:14:10 -07:00
Alex Waygood ceccc655db Introduce _typeshed.GenericPath and _typeshed.AnyStr_co (#7970) 2022-05-27 19:02:00 +01:00
Alex Waygood d511312e21 multiprocessing.managers: fix TypeVar usage (#7938)
#7928

`dict()` and `list()` just return empty dictionaries and lists (respectively) if no arguments are supplied:

```python
>>> from multiprocessing.managers import SyncManager
>>> with SyncManager() as s:
...     print(s.dict())
...
{}
```
2022-05-26 07:18:43 -07:00
Jelle Zijlstra d5bc48d29b builtins, collections: Fix unconstrained overloads for container constructors (#7944)
See https://github.com/microsoft/pyright/issues/3501#issuecomment-1135979479

Related to #7928
2022-05-25 10:07:23 +01:00
Jelle Zijlstra bd394d2486 builtins: add BaseException.add_note in py311 (#7860) 2022-05-17 20:32:28 -07:00
Shantanu a27f15ef0e builtins: reorder overloads (#7828)
This is slightly more friendly for --no-strict-optional (gross)
2022-05-11 01:00:52 -07:00
Shantanu 032787d867 builtins: accept old-style iterables to iter (#7817) 2022-05-10 09:06:31 +02:00
Jelle Zijlstra c93f262427 Add closure argument to exec() (#7793)
python/cpython#92204
2022-05-06 22:46:01 -07: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
Alex Waygood 7cbb579a44 Make __wrapped__ read-only on classmethods and staticmethods (#7694) 2022-04-25 22:27:06 -06:00
Alex Waygood 617d2aaf57 Fix crash when running mypy master against typeshed master (#7660) 2022-04-18 17:20:49 +01: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 97a74bc1aa Import from collections.abc wherever possible (#7635) 2022-04-18 12:50:37 +02: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 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 ee09d9eb19 builtins: Audit bytes arguments (#7631)
Most use the C buffer protocol, so _typeshed.ReadableBuffer is the right type. A few
check specifically for bytes and bytearray.
2022-04-16 14:16:11 +02:00
Alex Waygood 740193a8fc Use TypeAlias where possible for type aliases (#7630) 2022-04-15 18:01:00 -07:00
Jelle Zijlstra e0654bdbc0 ExceptionGroup: make it generic (#7626) 2022-04-15 16:24:17 +02:00
Joe Young d45c9084a4 Catch more potential type errors in builtins.sum (#7578)
Use a ` TypeVar` bound to a `Protocol` defining `__add__`
2022-04-01 23:19:05 +01:00
Alex Waygood a3245db63c Remove unneeded # noqa comments, fix broken # noqa comments (#7561) 2022-03-28 23:17:44 +02:00
Alex Waygood b63c963077 Use conditional overloads to simplify several stdlib functions (#7540) 2022-03-25 08:47:03 +01:00
Alex Waygood 4308915e06 Make __hash__ a ClassVar for several classes where it is set to None (#7485) 2022-03-19 05:59:10 -07:00
Alex Waygood 5c44ae4f8c Improve various signatures that shouldn't be async def, but currently are (#7491)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
2022-03-18 20:54:39 -07:00
Alex Waygood 3ab250eec8 Use PEP 604 syntax wherever possible (#7493) 2022-03-16 16:01:33 +01:00
Jelle Zijlstra 3e3cc2a6d6 dict.pop: Remove default for second argument (#7481)
The first overload takes care of the case where there is only one argument, so there should be no default in the second overload.
2022-03-13 13:11:35 +01:00
Alex Waygood 1a2f718ceb Make several fields read-only for type, staticmethod and classmethod (#7423) 2022-03-06 15:50:26 -08:00
Shantanu 9796b9ed69 Improve open overloads when mode is a literal union (#7428)
As pointed out by @gvanrossum in https://github.com/python/typing/issues/1096

Improves type inference in cases when we know that mode is
OpenBinaryMode, but don't know anything more specific:
```
def my_open(name: str, write: bool):
    mode: Literal['rb', 'wb'] = 'wb' if write else 'rb'
    with open(name, mode) as f:
        reveal_type(f)  # previously typing.IO[Any], now typing.BinaryIO
```

You may be tempted into thinking this is some limitation of type
checkers. mypy does in fact have logic for detecting if we match
multiple overloads and union-ing up the return types of matched
overloads. The problem is the last overload interferes with this logic.
That is, if you remove the fallback overload (prior to this PR), you'd get
"Union[io.BufferedReader, io.BufferedWriter]" in the above example.

Co-authored-by: hauntsaninja <>
2022-03-06 15:45:34 -08:00
Martin Fischer 5802e889c7 Correct str.__new__ argument name (#7422) 2022-03-02 12:20:45 +02:00
Alex Waygood 1ebedcc2b4 Mark fields as readonly in builtins.pyi and types.pyi (#7392)
Add FunctionType.__builtins__
2022-02-28 13:23:34 +01:00
Alex Waygood 4f0d8c593e Delete EnumMeta.__setattr__ and EnumMeta.__delattr__ (#7388) 2022-02-26 17:55:53 -08:00
Alex Waygood 2d6ab4d3bf Fix several mypy errors when run on the 3.11 stdlib (#7389) 2022-02-26 17:49:36 -08:00
Martin Fischer 51a3cf072c Add comments about mypy limitation regarding TypeVar constraints (#7350) 2022-02-22 12:29:39 +01:00
Shantanu 94127ca2f5 builtins: add __build_class__ (#7324) 2022-02-20 16:16:07 -08:00
Alex Waygood 5e8a2a9364 Fix various pos-only stubtest complaints previously allowlisted (#7228) 2022-02-15 17:51:34 +01:00
Alex Waygood f4967618dd Fix positional-only differences in many stdlib modules (#7226) 2022-02-15 15:14:06 +01:00
Alex Waygood a67c316d08 Add a few missing dunders in builtins (#7214) 2022-02-14 15:07:38 -08:00
Dmitry Volodin be5a109c03 Fix zero exponent for ints (#7163) 2022-02-08 14:08:00 -08:00