-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
The underlying C API that compile() uses to convert/validate its filename argument, PyUnicode_FSConverter, doesn't accept non-bytes buffers anymore (see python/cpython#98393), but typeshed still has that parameter typed with (collections.abc|typing_extensions).Buffer instead of bytes. Having a 3.12+ version if branch for the updated function definition would make sense, imo.
Min. Repro. Example
(.venv) thanos@DESKTOP-DERJ7DF:~$ python3.11 --version
Python 3.11.11
(.venv) thanos@DESKTOP-DERJ7DF:~$ python3.11 -c "compile('a=1', bytearray(b'<bytes>'), 'exec')"
<string>:1: DeprecationWarning: path should be string, bytes, or os.PathLike, not bytearray
(.venv) thanos@DESKTOP-DERJ7DF:~$ python3.12 --version
Python 3.12.9
(.venv) thanos@DESKTOP-DERJ7DF:~$ python3.12 -c "compile('a=1', bytearray(b'<bytes>'), 'exec')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: expected str, bytes or os.PathLike object, not bytearrayAt the moment, I can think of a few stdlib functions that pass a filename argument through to compile() and thus also need to be updated:
ast.parse()importlib.machinery.SourceFileLoader.source_to_code()(maybe also the corresponding methods in its base and/or child classes?)
Not sure what else is affected by this deprecation-turned-error, but there might be more.
UPDATE:
After going through the results of this search query, I think the only relevant compile() wrappers in the stdlib that need adjusting have already been mentioned.