Skip to content

Conversation

@Sachaa-Thanasius
Copy link
Contributor

@Sachaa-Thanasius Sachaa-Thanasius commented Oct 7, 2025

Fixes #13881.

Maybe warnings.deprecated() could be used here to deprecate non-bytes buffers as arguments, but I wanted to be initially conservative in the number of overloads this adds.

@github-actions

This comment has been minimized.

@Sachaa-Thanasius Sachaa-Thanasius marked this pull request as ready for review October 7, 2025 14:44
@Sachaa-Thanasius Sachaa-Thanasius changed the title Restrict the filename parameter of compile() (and other stdlib functions that use compile()) to only take bytes, not Buffer. Restrict filename parameter of compile() (and other stdlib functions wrapping compile()) to take bytes, not Buffer. Oct 7, 2025
@github-actions

This comment has been minimized.

@srittau
Copy link
Collaborator

srittau commented Oct 8, 2025

I'd say we shouldn't bother with the different version_info branches. Just use the more restrictive option. The possibility of someone using a non-bytes readable buffer and not wanting to fix it for Python < 3.12 are low, and I don't have much sympathy.

@Sachaa-Thanasius
Copy link
Contributor Author

Fair enough.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 8, 2025

Diff from mypy_primer, showing the effect of this PR on open source code:

altair (https://github.com/vega/altair)
+ altair/utils/execeval.py:81: error: Argument "filename" to "compile" has incompatible type "str | Buffer | PathLike[Any]"; expected "str | bytes | PathLike[Any]"  [arg-type]
+ altair/utils/execeval.py:87: error: Argument "filename" to "compile" has incompatible type "str | Buffer | PathLike[Any]"; expected "str | bytes | PathLike[Any]"  [arg-type]

@Sachaa-Thanasius
Copy link
Contributor Author

Sachaa-Thanasius commented Oct 8, 2025

The stubtest failures seem unrelated. Not sure why they're showing up now and not earlier. I suppose they're caused by #14851 and #14852 somehow.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@srittau srittau merged commit be7e7c5 into python:main Oct 8, 2025
60 of 63 checks passed
@Sachaa-Thanasius Sachaa-Thanasius deleted the restrict-compile-filename branch October 8, 2025 14:32
xen0n added a commit to xen0n/ruyi that referenced this pull request Nov 18, 2025
We are following the earlier signature, so it is no longer compatible
and pyright errors out on that. Fix by simply narrowing the `path`
argument's type.

Signed-off-by: WANG Xuerui <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3.12+: compile() and some wrappers of it don't accept non-bytes buffers for filename argument at runtime

2 participants