typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

Fix #13881: Add plugin to disallow bytearray as filename in compile()

Open vidhyavijayan3 opened this issue 8 months ago • 2 comments

In Python 3.12 and later, passing a bytearray as the filename argument to compile() is no longer allowed. This commit adds a mypy plugin that checks for this specific misuse and emits an appropriate error message.

The plugin is applied conditionally via mypy.ini and is compatible with the existing stubs for compile() in builtins.pyi.

This prevents false positives and ensures correct typing behavior in accordance with the updated CPython semantics.

Closes #13881

vidhyavijayan3 avatar May 27 '25 11:05 vidhyavijayan3

Please note that typeshed only provides type annotations, we don't need or want any custom mypy plugins – that would be detrimental to typeshed's purpose. To solve #13881, we just need to change the type annotations for compile's filename argument. ~~Probably to StrPath | bytes, but I haven't looked too deeply into it.~~ Probably StrOrBytesPath.

srittau avatar May 28 '25 08:05 srittau

Thank you for the clarification! I'll remove the custom mypy plugin and instead update the type annotation for the filename parameter in the compile() stub to use StrOrBytesPath, as suggested. Appreciate your feedback and guidance on aligning with typeshed's goals.

vidhyavijayan3 avatar May 28 '25 08:05 vidhyavijayan3