Skip to content

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
@github-actions

This comment has been minimized.

@srittau
Copy link
Collaborator

srittau commented Jul 10, 2024

There's a merge conflict in the allowlist now.

@github-actions

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

@github-actions

This comment has been minimized.

3 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

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.

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.

@github-actions

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.

@github-actions

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!

@github-actions

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!

@github-actions

This comment has been minimized.

@max-muoto
Copy link
Contributor Author

@srittau Thanks, implemented your feedback.

@github-actions
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