Commit Graph
304 Commits
Author SHA1 Message Date
Alex WaygoodandGitHub d92a6449c2 Remove more Python 3.8 cruft (#13787) 2025-04-03 11:56:38 +01:00
David PeterandGitHub ad8ecaf217 property.__get__: overload to model class-access behavior (#13769) 2025-04-02 15:09:56 +02:00
Joren HammudogluandGitHub 5513d3f19b Drop Python 3.8 support in builtins (#13762)
* remove py38 branches in `builtins`

* combined `builtins.dict` tests with those exclusive to `>=3.9`
2025-04-02 09:01:36 +02:00
Stephen MortonandGitHub 846d167f51 Fix default of dict.get (#13222) 2025-03-09 13:44:27 +01:00
AvasamandGitHub cc206f760d Drop flake8-noqa and remove workarounds to work with Ruff (#13571) 2025-03-03 15:48:59 +01:00
AvasamandGitHub 6d6e858e63 Enable Ruff PLC (Pylint Convention) (#13306) 2025-03-03 15:39:40 +01:00
Randolf ScholzandGitHub be17dc0ac4 builtins.slice: more precise __new__ overloads and defaults for StopT and StepT. (#13008) 2025-02-28 13:33:07 +01:00
David PeterandGitHub 15f98a8ab8 chr: Accept SupportsIndex argument (#13494)
The `chr` function does accept objects that implement the
`SupportsIndex` protocol. The [implementation] of the builtin method
calls `PyLong_AsLongAndOverflow` on the argument, which in turn calls
`__index__()`, if present. The parameter of the `chr` function can
therefore be annotated with `int | SupportsIndex`.

It seems to me like `SupportsIndex` alone would be enough, since `int`
implements `SupportIndex`, but I chose `int | SupportIndex` to make it
consistent with the annotations on `hex`, `oct` and `bin`.

[implementation]: https://github.com/python/cpython/blob/b05fa90b21dd01bb836285cdd41920320b09e681/Python/bltinmodule.c#L725
[PyLong_AsLongAndOverflow]: https://docs.python.org/3.13/c-api/long.html#c.PyLong_AsLongAndOverflow
2025-02-12 07:50:42 +00:00
Stephen MortonandGitHub 17408ee538 fix the __init__ of several C-classes (#13211) 2024-12-23 10:55:51 -08:00
bzoraclerandGitHub 9497f8aebf Remove value attribute from builtins.StopAsyncIteration (#13275) 2024-12-21 12:24:36 -08:00
Stephen MortonandGitHub 4aad825db3 fix the weird special builtins (#13213) 2024-12-08 00:18:15 +00:00
Stephen MortonandGitHub 11ec1a10fd Improve the SyntaxError constructor; add SyntaxError.print_file_and_line (#13141) 2024-11-27 22:21:48 +00:00
Joren HammudogluandGitHub 480b1ac2e6 Only accept type[Self] in the object.__class__ setter (#13021) 2024-11-18 12:34:36 +01:00
Rebecca ChenandGitHub ea368c7269 Type __call__ on builtins._NotImplementedType as None. (#12984)
Currently, this is intentionally incorrectly typed in order to produce a
better mypy error message. But pyright (and presumably other type checkers)
end up just treating instances of _NotImplementedType as callable.

With this change, the mypy error message gets a little worse, but other type
checkers can understand that instances of _NotImplementedType aren't
callable, which I think is an improvement.
2024-11-08 13:05:56 -08:00
Brian SchubertandGitHub dafd67c2cc Mark OSError.strerror as sometimes None (#12974) 2024-11-07 08:08:28 -08:00
Sam BullandGitHub 601ce5a4b0 OSError.errno can be None (#12910) 2024-10-27 20:51:23 +00:00
Randolf ScholzandGitHub 10183237c7 Make all params positional-only in slice.__new__ (#12900)
positional only __new__
2024-10-24 18:02:33 +01:00
ThanosandGitHub 65405e9ef2 Make slice generic (#11637) 2024-10-24 17:40:29 +02:00
AlbertXingZhangandGitHub 783171b9f7 correct memoryview __setitem__ method signature (#12876) 2024-10-24 12:09:38 +02:00
Stephen MortonandGitHub 925b3a3713 Remove redundant inheritances from Iterator in builtins (#12851) 2024-10-21 14:40:07 +02:00
bersbersbersandGitHub b78b3f10ba slice is hashable starting with Python 3.12 (#12832) 2024-10-17 09:17:38 +02:00
Jelle ZijlstraandGitHub 2370b8b9d1 memoryview: re-add inheritance from Sequence, set index and count to None (#12800)
This reverts commit f625e92ae5.
2024-10-16 07:27:56 -07:00
Max MuotoandGitHub 5fcd375815 Set default for enumerate's start argument (#12796) 2024-10-13 06:01:00 +02:00
Trim21andGitHub f625e92ae5 memoryview: remove inheritance from Sequence (#12781)
It doesn't have `index`, `count` or `__reversed__` methods
2024-10-11 17:47:51 +01:00
Pradeep KumarandGitHub b54dcc6783 [str] Add LiteralString overload for __getitem__ (#12714)
In PEP 675, Graham Bleaney and I had specified a list of `LiteralString`-preserving [overloads](https://peps.python.org/pep-0675/#appendix-c-str-methods-that-preserve-literalstring) for `str`. However, we didn't specify an overload for `__getitem__` and didn't give any rationale either. IIRC this was an edge case we didn't want to take a strong decision on unless users wanted it.

Carl Meyer brought this up yesterday, so I think it's worth discussing.

Pro: `my_literal_string[i]` or `my_literal_string[i:j]` should technically be compatible with `LiteralString`, since it is a substring of a literal-derived string.

Con: The main downside is that an attacker might control the indexes and try to access a specific substring from a literal string in the code. For example, they might narrow down the string to `rm foo` or `SELECT *`.

It's true that `join` and other methods could also construct dangerous strings from `LiteralString`s, and we even call that out as an accepted tradeoff in the PEP:

> 4. Trivial functions could be constructed to convert a str to a LiteralString:
>
>     def make_literal(s: str) -> LiteralString:
>         letters: Dict[str, LiteralString] = {
>             "A": "A",
>             "B": "B",
>             ...
>         }
>         output: List[LiteralString] = [letters[c] for c in s]
>         return "".join(output)
>
> We could mitigate the above using linting, code review, etc., but ultimately a clever, malicious developer attempting to circumvent the protections offered by LiteralString will always succeed. The important thing to remember is that LiteralString is not intended to protect against malicious developers; it is meant to protect against benign developers accidentally using sensitive APIs in a dangerous way (without getting in their way otherwise).
>
> Without LiteralString, the best enforcement tool API authors have is documentation, which is easily ignored and often not seen. With LiteralString, API misuse requires conscious thought and artifacts in the code that reviewers and future developers can notice.
>
> -- [PEP 675 - Appendix B: Limitations](https://peps.python.org/pep-0675/#appendix-b-limitations)

`__getitem__`, however, seems a bit different, because it (and `split`, `zfill`, etc.) accept an index or width that could be used to construct a dangerous query or a humongous string. So, we need to clarify the intent a little.

What was the intent of these overloads? We wanted to forbid "arbitrary user-supplied strings" while allowing methods that preserved literal strings. We were not trying to prevent every possible exploit on the string. Since `__getitem__` forbids arbitrary user-supplied strings and preserves literal strings, I think we should add an overload for it.
2024-10-01 20:29:00 -07:00
AvasamandGitHub 89e0b691db Enable more Ruff PYI rules with autofixes (#12557) 2024-09-04 19:50:07 -04:00
Sebastian RittauandGitHub 073b270e55 Update issues numbers for builtins.function (#12580) 2024-08-22 19:20:28 +02:00
937270df0c Forbid extremely long line lengths in non-autogenerated stubs (#12537)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-08-18 16:03:34 -04:00
sobolevnandGitHub 6f248dfa37 Bump mypy to 1.11.1 (#12463) 2024-08-04 23:19:28 -07:00
Tomas RandGitHub 964d1d73ae Add BaseException.__new__ (#12346) 2024-07-21 13:16:10 +02:00
Max MuotoandGitHub 4316e00c9e Make MemoryView Generic, make cast accurate (#12247) 2024-07-11 17:12:44 -07:00
b24dfccb74 Add defaults to the generic parameters of BaseExceptionGroup and ExceptionGroup (#12258)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
2024-07-11 06:11:19 -07:00
ShantanuandGitHub 73d5a55a32 Fixes for 3.13b3 (#12257)
Fixes #12255
2024-07-01 23:07:08 -07:00
Marc MuellerandGitHub 6dda799d8a Add type ignores for mypy 1.11 (#12177) 2024-06-20 15:49:50 +01:00
Alex WaygoodandGitHub fc33ba67ba builtins: updates for py313 (#12028) 2024-05-24 15:27:15 -04:00
Alex WaygoodandGitHub 4bc70e1e4d Use mypy from git for stdlib stubtest (#12016) 2024-05-23 13:08:18 -04:00
funkyrailroadandGitHub d75a47c2b7 Update BaseException and BaseExceptionGroup for 3.13 (#12010) 2024-05-23 10:44:41 -04:00
ShantanuandGitHub bb267c82f8 builtins: eval and exec can take globals and locals via keyword (#11934) 2024-05-17 23:55:16 +02:00
Sebastian RittauandGitHub ef0a5c2d12 Replace types._Cell with types.CellType (#11904)
Closes #11901
2024-05-12 06:38:38 -07:00
Jelle ZijlstraandGitHub 1dff589dd4 Use TypeIs for various stdlib functions (#11823) 2024-04-26 16:43:19 -07:00
Alex WaygoodandGitHub d0f2be92ab Bump pyright to v1.1.360 (#11810) 2024-04-24 14:09:16 +02:00
Jay QiandGitHub cc5f23ac14 Add init to NameError stub with name keyword argument (#11627)
Co-authored-by: Jay Qi <jayqi@users.noreply.github.com>

Closes #11626
2024-03-18 12:08:25 -06:00
1a942aa36d Replace Flake8 checks with Ruff (except for flake8-pyi) (#11496)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-03-10 14:35:45 +00:00
ShantanuandGitHub 470a13ab09 Use PEP 570 syntax in stdlib (#11250) 2024-03-09 14:50:16 -08:00
AvasamandGitHub 2116158891 Remove old type-ignore explanation comments not removed in #8280 (#11513) 2024-03-01 07:10:10 -08:00
Nikita SobolevandGitHub 675ab38ab7 Update pyright version to 1.1.350 (#11501)
If you're reading about this commit in an auto-generated changelog: this is an internal change that should have no impact on how these stubs are understood by static-analysis tools such as type checkers or IDEs
2024-02-29 10:14:39 +00:00
Nikita SobolevandGitHub 19d1b686b6 str.count only takes positional args (#11503)
```
>>> ''.count(x='a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: str.count() takes no keyword arguments
```
2024-02-29 10:37:12 +03:00
plokmijnuhbyandGitHub c5c2c14db9 builtins: Fix typing of reversed (#10655) 2024-02-16 06:52:58 -08:00
shz42andGitHub 2168ab5ff4 Add tuple key type for memoryview.__getitem__ and __setitem__ (#11296) 2024-01-21 05:14:34 +01:00
Alex WaygoodandGitHub ccc81f224d Bump various test dependencies (#11249) 2024-01-05 14:09:02 -08:00