Skip to content

Update xml's Callable[..., Element] types (tag param in __init__) #10968

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

Merged
merged 1 commit into from
Nov 3, 2023

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Nov 2, 2023

The tag param in __init__ is typed as str | Callable[..., Element], which really doesn't make sense to me looking at usages, and there's no comment explaining why. It really seems like the tag parameter of Element.__init__ should not be Callable.

Sidenote, even though Element.itertext does check for possible None self.tag, the docstring and documentation do suggest it should only be a str. So I left them as str and not str | None.

Relevant for #10967


Using re-assignement for PI (as implementation does) just leads to better method signatures.

class _HasTag(Protocol):
tag: Any # AnyOf[str, None, Callable[..., AnyOf[str, None]]]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This strange Union was caused by Element's typing leading me to believe it could be Callable and the runtime implementation leading me to believe it could be None (see PR description).
Looking at xml.etree._Element typing from lxml-stubs as well as implementation of openpyxl looks like this is never assumed to be None neither.

Copy link
Contributor

github-actions bot commented Nov 2, 2023

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

@srittau srittau merged commit 3a56e00 into python:main Nov 3, 2023
@Avasam Avasam deleted the xml-tag-Callable branch November 3, 2023 14:00
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