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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stdlib/xml/etree/ElementTree.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Element:
attrib: dict[str, str]
text: str | None
tail: str | None
def __init__(self, tag: str | Callable[..., Element], attrib: dict[str, str] = ..., **extra: str) -> None: ...
def __init__(self, tag: str, attrib: dict[str, str] = ..., **extra: str) -> None: ...
def append(self, __subelement: Element) -> None: ...
def clear(self) -> None: ...
def extend(self, __elements: Iterable[Element]) -> None: ...
Expand Down Expand Up @@ -132,7 +132,7 @@ def SubElement(parent: Element, tag: str, attrib: dict[str, str] = ..., **extra:
def Comment(text: str | None = None) -> Element: ...
def ProcessingInstruction(target: str, text: str | None = None) -> Element: ...

PI: Callable[..., Element]
PI = ProcessingInstruction

class QName:
text: str
Expand Down
4 changes: 3 additions & 1 deletion stubs/openpyxl/openpyxl/xml/_functions_overloads.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ _T_co = TypeVar("_T_co", covariant=True)

# Comment from openpyxl.cell.rich_text.py
# Usually an Element() from either lxml or xml.etree (has a 'tag' element)
# lxml.etree._Element
# xml.etree.Element
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.

tag: str

class _HasGet(Protocol[_T_co]):
def get(self, __value: str) -> _T_co | None: ...
Expand Down