psf / black

The uncompromising Python code formatter
https://black.readthedocs.io/en/stable/
MIT License
38.64k stars 2.43k forks source link

Support Python 3.13 free-threaded build #4438

Open ngoldbaum opened 1 month ago

ngoldbaum commented 1 month ago

Is your feature request related to a problem? Please describe.

It looks like everything is mostly working on the free-threaded build, except for three failing tests:

=========================== short test summary info ============================
FAILED tests/test_blackd.py::BlackDTestCase::test_normalizes_line_endings - AssertionError: '[Errno 24] Too many open files' != 'c\r\nc\r\n'
FAILED tests/test_blackd.py::BlackDTestCase::test_preserves_line_endings - OSError: [Errno 24] Too many open files
FAILED tests/test_blackd.py::BlackDTestCase::test_single_character - OSError: [Errno 24] Too many open files
================== 3 failed, 372 passed, 3 skipped in 32.93s ===================

This is with a version of black I built using the free-threaded build of Python3.13.0rc1. I ran the tests with PYTHON_GIL=0 to force the GIL to be disabled. I also built aiohttp with an updated version of cython (see https://github.com/aio-libs/aiohttp/issues/8796).

You should be able to follow https://py-free-threading.github.io/porting/ to declare that C extensions support running without the GIL, assuming there are no known or suspected thread safety issues.

Describe the solution you'd like

Supporting free-threaded Python without any special hacking.

JelleZijlstra commented 1 month ago

Our C extension is built with mypyc, so I'd prefer a solution inside mypyc rather than something special we do ourselves.

Until mypyc supports free-threading, users using free-threading should be able to use our pure-Python wheel; I don't think mypyc even supports 3.13 with the GIL yet.

JelleZijlstra commented 1 month ago

Also, the tests you flag depend on aiohttp; I wonder if the failures are because aiohttp doesn't support free-threading yet.

ngoldbaum commented 1 month ago

I see 3.13 support is being tracked over at https://github.com/mypyc/mypyc/issues/1056.