Commit Graph

56 Commits

Author SHA1 Message Date
Alex Waygood
6ed392ba5f Make `type()` method params positional-only (#6238) 2021-11-04 11:48:34 -07:00
Alex Waygood
d0964d2221 Make super() parameters positional-only (#6237) 2021-11-04 11:13:41 -07:00
Alex Waygood
aa9cd1e80e Make `range` parameters positional-only (#6236) 2021-11-04 10:56:16 -07:00
Alex Waygood
4cbc657167 Make getattr() parameters positional-only (#6235) 2021-11-04 18:28:33 +01:00
Alex Waygood
26f2c702d3 Make slice parameters positional-only (#6234) 2021-11-04 15:29:15 +01:00
Alex Waygood
e2ee7c297d Make property method args positional-only (#6231) 2021-11-03 09:33:08 -07:00
Kyle Altendorf
9052674aa8 bytes.fromhex() returns cls instance, not bytes (#6201)
```console
$ cat y.py
import typing

class MyBytes(bytes):
    pass


x = MyBytes.fromhex("abcd")
if typing.TYPE_CHECKING:
    reveal_type(x)
else:
    print(x.__class__.__name__)
```

```console
$ for v in 3.6 3.7 3.8 3.9 3.10; do echo -n "$v: " ; python$v y.py; done
3.6: MyBytes
3.7: MyBytes
3.8: MyBytes
3.9: MyBytes
3.10: MyBytes
```

```console
$ venv/bin/mypy y.py
y.py:9: note: Revealed type is "builtins.bytes"
```
2021-10-25 16:28:33 -07:00
Akuli
994b69ef8f Use lowercase tuple where possible (#6170) 2021-10-14 17:18:19 -07:00
Marti Raudsepp
c38c03bab8 builtins: next() does not allow keyword args for default (#6169) 2021-10-14 09:51:58 +02:00
Shantanu
55cf343ba9 zip: update for PEP 618 (#6123)
Resolves #6122

Co-authored-by: hauntsaninja <>
2021-10-06 12:54:47 -07:00
Akuli
196f69b27e dict.__init__: support dict(string.split(sep) for string in iterable) (#6050) 2021-09-20 13:52:41 +02:00
KotlinIsland
1b5c4e1d57 Add support for dict.{keys,values,items}.mapping (#6039)
Co-authored-by: KotlinIsland <kotlinisland@users.noreply.github.com>
2021-09-19 22:30:14 -07:00
Sebastian Rittau
b562d233ae (a)next only requires __(a)next__, not Iterator (#6036) 2021-09-14 11:43:21 +03:00
Gabe Joseph
92aecadf6b Memoryview.cast: shape= can be tuple of any number of ints (#5918) 2021-08-13 00:04:35 +02:00
Bas van Beek
7edad1034e Use a typevar in object.__new__ (#5891) 2021-08-08 20:45:22 +02:00
Akuli
ce11072dbe Big diff: use lower-case list and dict (#5888) 2021-08-08 09:26:35 -07:00
Akuli
ef5b4b6820 setattr: Any --> object (#5877) 2021-08-08 11:12:23 +02:00
Akuli
ee487304d7 Big diff: Use new "|" union syntax (#5872) 2021-08-08 11:05:21 +02:00
Ron Frederick
309e7bda32 Update builtins.pyi (#5874)
Change getattr/hasattr first argument from Any to object

Fixes #5848
2021-08-07 20:46:03 -07:00
Bas van Beek
475417fa97 Mark final and unhashable classes in types as such (#5837) 2021-08-02 13:46:14 -07:00
Bas van Beek
7c37d6117d Allow reversed to take any object implementing __len__ and __getitem__ (#5820)
`reversed` is currently annotated as accepting either a `Sequence` or objects implementing the `__reversed__` protocol.
This however is too strict as, per its [docs](https://docs.python.org/3/library/functions.html#reversed), it can take any object that implements `__len__` and `__getitem__`.
2021-07-29 07:48:14 -07:00
Bas van Beek
5e23e2c19a Use SupportsIndex where applicable in builtins.pyi (#5739)
* Use `SupportsIndex` where applicable in `builtins.pyi`

* Remove `None` from the `int.__round__` ndigits parameter
2021-07-09 13:08:19 +03:00
Akuli
b06352556d Use Literal["little", "big"] for byteorder (#5715) 2021-06-30 13:15:50 -07:00
Anton Grübel
c38171a0b3 Use _typeshed.Self with __enter__ (#5712) 2021-06-29 15:19:25 -07:00
Bas van Beek
50f5858a56 Use SupportsIndex where applicable for 5 classes (#5694)
Use `SupportsIndex` where applicable:

* `str`
* `bytes`
* `bytearray`
* `memoryview`
* `markupsafe.Markup`
2021-06-26 19:05:40 +03:00
Sebastian Speitel
04d81a8499 Allow merging dicts of different types (#5520) 2021-06-16 06:03:15 -07:00
Ethan Smith
cb76f32826 Allow passing complex to complex constructor (#5609) 2021-06-09 22:58:22 +02:00
Shantanu
04fb7ceb3c builtins: add a getattr overload for bool (#5518)
As brought up in https://github.com/python/typeshed/pull/5516

Alternatives include:
- Use another type var that has a value restriction
- Doing something fancy with Protocols that have a __bool__ that returns
  a Literal (which may not work)
- Doing nothing
2021-05-29 07:09:38 -07:00
Jelle Zijlstra
c4da3757d7 Improve tuple.__add__ type (#5522)
Noticed this while browsing the stub. This feels safe but we'll see what mypy-primer has to say.
2021-05-26 22:17:30 +02:00
Neil Vyas
8d56328a24 change getattr stubs to better type the default argument and return type (#5516)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Akuli <akuviljanen17@gmail.com>
2021-05-21 16:44:11 -07:00
Andrey
dbaaa3a103 PEP 604: Add ror operator and modify isinstance and subclass (#5509)
Add operators or and ror for types.Union and ror to the type class.
Also, add modified isinstance and issubclass signatures to support old-style and new-style unions inside.
2021-05-21 16:30:27 -07:00
Sebastian Rittau
acca3181ed Improve dict.fromkeys() with None value (#5514)
Closes: #5512
2021-05-21 20:30:33 +03:00
Sebastian Rittau
f0bf6eebbd AnyStr cleanup (#5487)
* Replace all uses of StrPath, BytesPath, and AnyPath in Python 2 stubs.
* Add StrOrBytesPath as preferred alias for AnyPath.
* Replace all remaining AnyPath instances with StrOrBytesPath.
* Mark AnyPath as obsolete.

Part of #5470
2021-05-17 20:45:48 +02:00
Adrian Freund
a2058829fa Make memoryview inherit from Sequence (#5393) 2021-05-10 12:46:17 +02:00
sachindavra
1048250c04 ror implementation (#5369)
Signed-off-by: sachindavra <raju.davra@gmail.com>
2021-05-07 21:10:07 +03:00
James
dbaf4c6390 Improve `type.__new__` (#5331)
Fixes #3386
2021-05-03 18:33:29 -07:00
Shantanu
1517438aba builtins: more updates for py310 (#5290) 2021-05-01 21:58:39 -07:00
Shantanu
0ea437f02a builtins: use SupportsLessThan over SupportsLessThanT if possible (#5288)
Co-authored-by: hauntsaninja <>
2021-05-01 21:39:25 -07:00
Eric Traut
58e083fef9 Marked the bool class as @final because it cannot be subclassed. (#5286)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2021-05-01 21:38:10 -07:00
Shantanu
445a86f4c9 builtins: add aiter, anext (#5289) 2021-05-01 21:10:30 -07:00
Sebastian Rittau
4ac3ccad45 black: enable skip_magic_trailing_comma (#5252)
* black: enable skip_magic_trailing_comma

* Remove spurious commas
2021-04-27 08:32:32 -07:00
Sebastian Rittau
bac1918b5f PathLike cleanup (#5242)
Copy builtins._PathLike to os.PathLike

Use os.PathLike exclusively outside of builtins
2021-04-23 10:15:07 -07:00
hatal175
fc0775664d Use native SupportsIndex in builtins (#5229) 2021-04-20 22:24:39 -07:00
hatal175
f44f38fda3 Fixes #1110. Use SupportsIndex in str, bytes and bytesarray functions wh… (#5228)
* Fixes #1110. Use SupportsIndex in str, bytes, bytesarray functions where applicable.
2021-04-17 22:27:58 +03:00
hatal175
d3b2cafa85 builtins stubtest exceptions (#5219) 2021-04-16 10:41:04 -07:00
Andrey
31d1c30606 PEP 604: Add or operator to class type (#5151)
Co-authored-by: andrey.matveev <andrey.matveev@jetbrains.com>
2021-04-08 07:45:31 -07:00
Sebastian Rittau
29061d36ae Fix dict type if constructing with kwargs (#4987)
Closes #4846
2021-03-22 19:30:01 -07:00
Eric Traut
29c3d67626 Improved definition of divmod function in builtins (#5114)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2021-03-15 11:10:09 +01:00
Jelle Zijlstra
30fc2b8cd0 fix positional-only arguments to str and bytes (#5112) 2021-03-12 15:33:25 -08:00
Andrew Crabtree
a3cfb4e507 Add missing msg type to ImportError (#5111)
Fixes #5107
2021-03-12 11:20:46 -08:00