Commit Graph

5818 Commits

Author SHA1 Message Date
sobolevn
d16fe74e1f Fix _csv.Dialect.__init__ (#12320) 2024-10-03 11:33:56 +02:00
Sebastian Rittau
975760281c tarfile.open(): Handle all modes (#12181) 2024-10-02 20:35:56 -07:00
Alex Waygood
45f96fe343 Move multiprocessing test-case file to the right place (#12727) 2024-10-02 16:36:24 +01:00
Sebastian Rittau
e4c84dfb11 Make email.policy classes generic (#12724) 2024-10-02 16:42:07 +02:00
Sebastian Rittau
f266dc226a Change RawIOBase return types from None to MaybeNone (#12686) 2024-10-02 07:11:23 -07:00
Stephen Morton
719ddd1774 move re.error into re.pyi (#11188) 2024-10-02 11:26:44 +02: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
Stephen Morton
4f37d8fff8 add _ssl module (#11155)
Really all I needed for fixing the inheritance was _ssl._SSLContext.
But then I needed all the other stuff in _ssl, and if I was doing that
I wanted to do a thorough job of it.

Motivation was originally related to https://github.com/python/typeshed/issues/3968 ,
but we're well beyond that now, really.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-10-01 20:10:51 -07:00
Stephen Morton
c43894568f resort weakref classes (#11165)
This improves fidelity of naming and inheritance on 3.11+

related to https://github.com/python/typeshed/issues/3968 and https://github.com/python/typeshed/issues/11141

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-10-01 19:50:10 -07:00
Stephen Morton
6bc1884577 follow implementation more closely in zoneinfo (#11189)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-10-01 19:49:01 -07:00
Stephen Morton
ddb57608fd move pyexpat.ExpatError to xml.parsers.expat.ExpatError (#11168)
This matches the name reported by the cass at runtime.

related to https://github.com/python/typeshed/issues/11141

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-10-01 18:45:11 -07:00
Avasam
bdb5b52d50 Make multiprocessing pipes generic (#11137) 2024-10-01 18:11:42 -07:00
Dima Tisnek
c47650323e fix: correct headers= kwarg in HTTP[S]Connection (#12704) 2024-10-01 08:59:46 +02:00
Semyon Pupkov
06b50fcc27 Fix yeardatescalendar, yeardays2calendar, yeardayscalendar return types (#12703) 2024-09-30 13:47:49 +02:00
Victorien
db265afec5 Use Mapping for local Python namespace parameters (#12705) 2024-09-30 11:26:41 +02:00
Akuli
13a74a5211 Update tkinter.Text.count() for Python 3.13 (Akuli's version) (#12629) 2024-09-24 23:08:11 -07:00
Martin Huschenbett
46512118ea Return coroutine from AsyncGenerator.__anext__ (#12685)
The `__anext__` method of an asynchronous generator defined using the
`async def`/`yield` syntax returns an actual coroutine not just any
awaitable. Let the definition of the `AsyncGenerator` protocol reflect
this circumstance.

See https://discuss.python.org/t/types-for-asynchronous-generators-too-general/64515
for the motivation behind this change.
2024-09-23 11:34:56 +02:00
Max Muoto
85121de466 Update importlib resources for 3.13 (#12298) 2024-09-16 20:21:35 +02:00
Max Muoto
dbe4d32a2a Add fchmod and lchmod for Windows on 3.13 (#12662) 2024-09-15 22:13:09 +02:00
Max Muoto
29c8026910 Add missing winapi functions for 3.13 (#12658) 2024-09-14 12:01:42 +02:00
Max Muoto
f190a1f213 Remove ParamSpec for SupportsReplace (#12410) 2024-09-14 11:42:30 +02:00
Max Muoto
eaeb56ffcf Add missing winapi constants for 3.13 (#12657) 2024-09-14 11:39:22 +02:00
Max Muoto
9e787769c6 Remove _msi in 3.13 (#12659) 2024-09-14 11:20:49 +02:00
Max Muoto
53d4877071 Move __replace__ issues out of triage (#12656) 2024-09-13 22:39:34 -07:00
Sebastian Rittau
a29d6710a5 Move platform-specific allowlist entries (#12644) 2024-09-12 11:04:07 +02:00
Sebastian Rittau
c7c430857e stdlib updates for latest Python patch releases (#12638) 2024-09-11 17:58:24 +02:00
Max Muoto
089953ed84 Fix doctest for 3.13 (#12625) 2024-09-08 12:38:13 +02:00
Adam Dangoor
61ed105cdb Mark _TemporaryFileWrapper argument as positional-only (#12624)
The following code errors at runtime:

```python
import tempfile

with tempfile.NamedTemporaryFile() as f:
	f.write(s=b"")
```

```
TypeError: BufferedRandom.write() takes no keyword arguments
```
2024-09-07 02:33:02 -07:00
Avasam
0784bf6bee distutils: add missing generated attributes (#12467) 2024-09-06 15:07:44 -07:00
Sebastian Rittau
cc45a6e9ba Move BufferedIOBase.raw to sub-classes (#12571) 2024-09-06 15:03:08 -07:00
Sebastian Rittau
6441408aaa Use TypedDict for return type of localeconv() (#12600)
Mark constants as Final in _locale.pyi
2024-09-05 02:13:41 +02:00
Avasam
89e0b691db Enable more Ruff PYI rules with autofixes (#12557) 2024-09-04 19:50:07 -04:00
Tomas R
6b1566d81c Fix signature of CodecInfo.decode (#12610)
Co-authored-by: Akuli <akuviljanen17@gmail.com>
2024-09-01 20:28:13 +03:00
Vito De Tullio
4507d26ef2 curses: mark keypad yes parameter as positional only (#12605)
matches the runtime check: "TypeError: window.keypad() takes no keyword arguments"
2024-09-01 20:20:31 +03:00
Avasam
f87041e118 distutils: expose Command.dry_run + make 0|1 attrs bool (#12607) 2024-08-30 18:32:54 +02:00
Peter Bierma
1a59cc28ba Add complex arithmetic types to ctypes (#12480) 2024-08-29 17:27:37 +02:00
Max Muoto
63db21eaa0 Add __replace__ for AST and AST subclasses (#12486) 2024-08-29 17:25:54 +02:00
Max Muoto
ad6eed0777 Add _thread.start_joinable_thread and _thread.lock for 3.13 (#12588) 2024-08-29 17:20:02 +02:00
Max Muoto
70e9748f18 Fix _thread.interrupt_main for 3.10+ (#12586) 2024-08-29 17:10:17 +02:00
Sebastian Rittau
039c6bcdb1 Use Self for email.message attachments (#12530)
---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Avasam <samuel.06@hotmail.com>
2024-08-29 10:48:32 -04:00
Sebastian Rittau
073b270e55 Update issues numbers for builtins.function (#12580) 2024-08-22 19:20:28 +02:00
Avasam
98af3eb9da Add unittest.runner._WritelnDecorator (#12407) 2024-08-22 09:50:31 +02:00
Sebastian Rittau
7865a78de1 socketserver: Use BufferedIOBase instead of BinaryIO (#12568) 2024-08-21 19:25:06 -07:00
Avasam
3719f02dbf Using precise code for pyright: ignore and re-enabling various pyright tests (#12576) 2024-08-22 03:34:52 +02:00
Sebastian Rittau
7f38b116a0 Remove redundant overloads from IO (#12570) 2024-08-21 15:55:22 +02:00
Kevin Van Brunt
86e74163b9 Fix DatagramRequestHandler.packet type hint. (#12563) 2024-08-21 12:53:49 +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
Peter Bierma
eb8e9ddd91 Add stubs for operator.is_none and operator.is_not_none (#12535)
Co-authored-by: Akuli <akuviljanen17@gmail.com>
2024-08-18 00:09:54 +03:00
Max Muoto
82da1e19a7 Use Final in tkinter (#12545) 2024-08-17 22:34:16 +02:00
Max Muoto
9ecd07a669 Use Final for Pre-Defined Hashing Methods in crypt (#12544) 2024-08-17 22:15:05 +02:00