Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update importlib resources for 3.13 #12298

Merged
merged 68 commits into from
Sep 16, 2024
Merged

Conversation

max-muoto
Copy link
Contributor

@max-muoto max-muoto commented Jul 9, 2024

Update importlib.resources based on 3.13 API changes: python/cpython#116609

@max-muoto max-muoto marked this pull request as draft July 9, 2024 04:00
if sys.version_info >= (3, 13):
def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ...
@overload
def open_text(anchor: Anchor, *path_names: *tuple[StrPath], encoding: str = "utf-8", errors: str = "strict") -> TextIO: ...
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If one path name is provided, the encoding defaults to utf-8, otherwise it's required: https://github.com/python/cpython/blob/3.13/Lib/importlib/resources/_functional.py#L67

@max-muoto max-muoto marked this pull request as ready for review July 9, 2024 04:27

This comment has been minimized.

@srittau
Copy link
Collaborator

srittau commented Jul 10, 2024

There's a merge conflict in the allowlist now.

This comment has been minimized.

Comment on lines 28 to 31
Package: TypeAlias = str | ModuleType

if sys.version_info >= (3, 11):
Resource: TypeAlias = str
else:
if sys.version_info >= (3, 13):
Anchor: TypeAlias = Package
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd put these into ._common, like in the implementation (introduced in Python 3.11). Or at least Anchor, since it was newly introduced.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed! 9cc4585

This comment has been minimized.

3 similar comments

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@max-muoto
Copy link
Contributor Author

@srittau It seems we're still running stubtest on importlib.resources._functional even though it only exists on 3.13+, does this seem right to you?

@srittau
Copy link
Collaborator

srittau commented Jul 15, 2024

I've added two suggestions that will hopefully help.

@@ -204,3 +194,7 @@ codecs.namereplace_errors
codecs.replace_errors
codecs.strict_errors
codecs.xmlcharrefreplace_errors

# Runtime dynamically renames kwargs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment has been minimized.

@srittau
Copy link
Collaborator

srittau commented Jul 16, 2024

Looking at the code in mypy_test, it seems that we are not actually handling sub-modules at all when it comes to the VERSIONS file. I will send a PR.

This comment has been minimized.

@srittau
Copy link
Collaborator

srittau commented Jul 16, 2024

The mypy errors are gone now. I have some ideas about fixing the pyright test, but I need to find some time in the next few days.

@max-muoto
Copy link
Contributor Author

The mypy errors are gone now. I have some ideas about fixing the pyright test, but I need to find some time in the next few days.

Thanks!

This comment has been minimized.

@max-muoto
Copy link
Contributor Author

I think the easiest solution for now is to add stdlib/importlib/resources/_functional.pyi to the exclude list of pyrightconfig.stricter.json (with an appropriate comment).

I ended up just nesting the imports under additionally type-checking blocks. While a bit more verbose, I think it works well so we can avoid false unrelated false negatives in these files. Let me know what you think!

This comment has been minimized.

stdlib/@tests/test_cases/check_importlib_resources.py Outdated Show resolved Hide resolved
stdlib/importlib/resources/__init__.pyi Outdated Show resolved Hide resolved
stdlib/importlib/resources/__init__.pyi Outdated Show resolved Hide resolved
stdlib/importlib/resources/__init__.pyi Outdated Show resolved Hide resolved
stdlib/importlib/resources/__init__.pyi Outdated Show resolved Hide resolved
max-muoto and others added 6 commits September 16, 2024 12:29
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
@max-muoto
Copy link
Contributor Author

@srittau Thanks, implemented your feedback.

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau merged commit 85121de into python:main Sep 16, 2024
63 checks passed
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.

2 participants