Commit Graph

322 Commits

Author SHA1 Message Date
Brian Schubert b2777f4cbb Mark stub-only types with runtime aliases as @type_check_only in stdlib (#14717) 2025-09-14 19:57:39 +02:00
Jelle Zijlstra bf484ab320 Add @disjoint_base to builtins.tuple (#14683) 2025-09-07 00:36:57 +01:00
Jelle Zijlstra e8ba06f710 Add @disjoint_base decorator in the stdlib (#14599)
And fix some other new stubtest finds.
2025-08-24 07:27:14 -07:00
Brian Schubert 953e21bafa Add __format__ overrides to complex, float, int, and str (#14523) 2025-08-05 17:56:36 -04:00
Brian Schubert 622df68c1c Add @type_check_only to stub-only private classes in stdlib (#14512) 2025-08-03 10:13:16 +02:00
Sebastian Rittau 7e16c80989 Remove some pytype workarounds from stdlib (#14470)
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>
2025-07-27 11:56:26 +01:00
Brian Schubert f88a09d479 Add @type_check_only to various typeshed-only procotols in stdlib (#14465)
Mark various typeshed-only protocols as `@type_check_only` in stdlib
2025-07-26 20:02:17 +01:00
David Peter f64707592d bytes.translate: generalize delete parameter type (#14372)
bytes.translate: generalize 'delete' parameter type
2025-07-07 00:19:23 -07:00
Sebastian Rittau 033c85df99 Remove old cycle-prevention workaround (#14180)
This was used to prevent an import cycle that exists
anyway nowadays via `_typeshed`.
2025-05-28 11:31:36 +02:00
sobolevn d574139e6c Update builtins to 3.14 (#14161) 2025-05-26 15:47:09 -07:00
sobolevn 204ec1273f Correct bool.__invert__ deprecation message (#14147) 2025-05-26 11:12:26 +02:00
Max Muoto 9ea05e6289 Add missing builtin dunders (3.14) (#14120) 2025-05-21 21:52:35 -07:00
Max Muoto 1c5164f069 Add from_number for float, complex, and Fraction (3.14) (#14091) 2025-05-17 22:09:59 -07:00
Jelle Zijlstra 9430260770 builtins: improve builtins.function (#14094)
Remove two differences from types.FunctionType that should be
safe to clean up.
2025-05-17 19:43:22 +02:00
Max Muoto 7fbf9c7927 Update exception group to match clinic generated arguments (#14088) 2025-05-16 20:50:00 -07:00
Sebastian Rittau b444909873 Copy typechecker-internal symbols to _typeshed._type_checker_internals (#13816) 2025-05-11 16:07:53 +02:00
Jelle Zijlstra 5ff32f377c 3.14: add annotationlib, update typing and inspect (#13985) 2025-05-10 14:25:06 -07:00
Max Muoto b64e741a4a Add strict argument for map (3.14) (#13987) 2025-05-10 20:21:41 +02:00
Alex Waygood d92a6449c2 Remove more Python 3.8 cruft (#13787) 2025-04-03 11:56:38 +01:00
David Peter ad8ecaf217 property.__get__: overload to model class-access behavior (#13769) 2025-04-02 15:09:56 +02:00
Joren Hammudoglu 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 Morton 846d167f51 Fix default of dict.get (#13222) 2025-03-09 13:44:27 +01:00
Avasam cc206f760d Drop flake8-noqa and remove workarounds to work with Ruff (#13571) 2025-03-03 15:48:59 +01:00
Avasam 6d6e858e63 Enable Ruff PLC (Pylint Convention) (#13306) 2025-03-03 15:39:40 +01:00
Randolf Scholz be17dc0ac4 builtins.slice: more precise __new__ overloads and defaults for StopT and StepT. (#13008) 2025-02-28 13:33:07 +01:00
David Peter 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 Morton 17408ee538 fix the __init__ of several C-classes (#13211) 2024-12-23 10:55:51 -08:00
bzoracler 9497f8aebf Remove value attribute from builtins.StopAsyncIteration (#13275) 2024-12-21 12:24:36 -08:00
Stephen Morton 4aad825db3 fix the weird special builtins (#13213) 2024-12-08 00:18:15 +00:00
Stephen Morton 11ec1a10fd Improve the SyntaxError constructor; add SyntaxError.print_file_and_line (#13141) 2024-11-27 22:21:48 +00:00
Joren Hammudoglu 480b1ac2e6 Only accept type[Self] in the object.__class__ setter (#13021) 2024-11-18 12:34:36 +01:00
Rebecca Chen 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 Schubert dafd67c2cc Mark OSError.strerror as sometimes None (#12974) 2024-11-07 08:08:28 -08:00
Sam Bull 601ce5a4b0 OSError.errno can be None (#12910) 2024-10-27 20:51:23 +00:00
Randolf Scholz 10183237c7 Make all params positional-only in slice.__new__ (#12900)
positional only __new__
2024-10-24 18:02:33 +01:00
Thanos 65405e9ef2 Make slice generic (#11637) 2024-10-24 17:40:29 +02:00
AlbertXingZhang 783171b9f7 correct memoryview __setitem__ method signature (#12876) 2024-10-24 12:09:38 +02:00
Stephen Morton 925b3a3713 Remove redundant inheritances from Iterator in builtins (#12851) 2024-10-21 14:40:07 +02:00
bersbersbers b78b3f10ba slice is hashable starting with Python 3.12 (#12832) 2024-10-17 09:17:38 +02:00
Jelle Zijlstra 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 Muoto 5fcd375815 Set default for enumerate's start argument (#12796) 2024-10-13 06:01:00 +02:00
Trim21 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 Kumar 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
Avasam 89e0b691db Enable more Ruff PYI rules with autofixes (#12557) 2024-09-04 19:50:07 -04:00
Sebastian Rittau 073b270e55 Update issues numbers for builtins.function (#12580) 2024-08-22 19:20:28 +02:00
Avasam 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
sobolevn 6f248dfa37 Bump mypy to 1.11.1 (#12463) 2024-08-04 23:19:28 -07:00
Tomas R 964d1d73ae Add BaseException.__new__ (#12346) 2024-07-21 13:16:10 +02:00
Max Muoto 4316e00c9e Make MemoryView Generic, make cast accurate (#12247) 2024-07-11 17:12:44 -07:00
Kanishk Pachauri 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