Commit Graph

294 Commits

Author SHA1 Message Date
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
Shantanu
73d5a55a32 Fixes for 3.13b3 (#12257)
Fixes #12255
2024-07-01 23:07:08 -07:00
Marc Mueller
6dda799d8a Add type ignores for mypy 1.11 (#12177) 2024-06-20 15:49:50 +01:00
Alex Waygood
fc33ba67ba builtins: updates for py313 (#12028) 2024-05-24 15:27:15 -04:00
Alex Waygood
4bc70e1e4d Use mypy from git for stdlib stubtest (#12016) 2024-05-23 13:08:18 -04:00
funkyrailroad
d75a47c2b7 Update BaseException and BaseExceptionGroup for 3.13 (#12010) 2024-05-23 10:44:41 -04:00
Shantanu
bb267c82f8 builtins: eval and exec can take globals and locals via keyword (#11934) 2024-05-17 23:55:16 +02:00
Sebastian Rittau
ef0a5c2d12 Replace types._Cell with types.CellType (#11904)
Closes #11901
2024-05-12 06:38:38 -07:00
Jelle Zijlstra
1dff589dd4 Use TypeIs for various stdlib functions (#11823) 2024-04-26 16:43:19 -07:00
Alex Waygood
d0f2be92ab Bump pyright to v1.1.360 (#11810) 2024-04-24 14:09:16 +02:00
Jay Qi
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
Avasam
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
Shantanu
470a13ab09 Use PEP 570 syntax in stdlib (#11250) 2024-03-09 14:50:16 -08:00
Avasam
2116158891 Remove old type-ignore explanation comments not removed in #8280 (#11513) 2024-03-01 07:10:10 -08:00
Nikita Sobolev
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 Sobolev
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
plokmijnuhby
c5c2c14db9 builtins: Fix typing of reversed (#10655) 2024-02-16 06:52:58 -08:00
shz42
2168ab5ff4 Add tuple key type for memoryview.__getitem__ and __setitem__ (#11296) 2024-01-21 05:14:34 +01:00
Alex Waygood
ccc81f224d Bump various test dependencies (#11249) 2024-01-05 14:09:02 -08:00
Sebastian Rittau
53a8193d64 Update typing_extensions imports in stdlib (#11244)
Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
2024-01-05 08:15:19 -08:00
Sebastian Rittau
23604858a6 Remove Python 3.7 branches (#11238) 2024-01-05 11:39:39 +01:00
Shantanu
6fcd37456d Move ellipsis definition to types (#11223) 2024-01-02 16:14:53 -08:00
Simon Lanzmich
fe48f37bf7 stdlib: Annotate type.__prepare__ to return a mutable object (#11093)
During class creation, the namespace returned by `__prepare__` is
populated when the class body is executed. Therefore, it must be
mutable.
2023-12-03 22:46:33 +00:00
Alex Waygood
10febc4fe0 stdlib: remove unused type: ignore comments (#11061) 2023-11-23 14:00:07 +01:00
Jelle Zijlstra
c2c8d7cf5d stdlib: Apply some simple deprecations (#11044) 2023-11-23 09:03:01 +01:00
Xuehai Pan
aa15fafc33 stdlib: builtins.type.__base__ can be None (#11040) 2023-11-18 14:03:56 +00:00
Jelle Zijlstra
4deef7550f stdlib: Fix more signatures with unrepresentable defaults (#11007) 2023-11-09 18:20:09 -08:00
Jelle Zijlstra
d9311f946e stdlib: fix signatures for some functions with unrepresentable defaults (#11000)
Found with python/mypy#16433

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-11-09 08:14:36 -08:00
Sebastian Rittau
a5c1a4cd3f Introduce _typeshed.SupportsFlush (#10983) 2023-11-06 15:31:02 +01:00