Skip to content

Commit fe48d5d

Browse files
committed
fix(stub): Sort out QName construct arg combinations
- 1st arg can't be bytearray - 2nd arg can be bytearray but not QName - empty string causes exception
1 parent 10624a5 commit fe48d5d

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

src/lxml-stubs/etree/_module_misc.pyi

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import sys
66
from abc import ABCMeta, abstractmethod
7-
from typing import Final, overload
7+
from typing import Any, Final, Literal, overload
88

99
from .._types import (
1010
_ElementOrTree,
@@ -20,6 +20,11 @@ if sys.version_info >= (3, 11):
2020
else:
2121
from typing_extensions import LiteralString
2222

23+
if sys.version_info >= (3, 13):
24+
from warnings import deprecated
25+
else:
26+
from typing_extensions import deprecated
27+
2328
DEBUG: int
2429
ICONV_COMPILED_VERSION: Final[tuple[int, int]]
2530
LIBXML_COMPILED_VERSION: Final[tuple[int, int, int]]
@@ -91,40 +96,36 @@ class DocInfo:
9196
class QName:
9297
"""QName wrapper for qualified XML names.
9398
94-
Pass a tag name by itself or a namespace URI and a tag name to
95-
create a qualified name. Alternatively, pass an Element to
96-
extract its tag name. ``None`` as first argument is ignored in
97-
order to allow for generic 2-argument usage.
98-
99-
The ``text`` property holds the qualified name in
100-
``{namespace}tagname`` notation. The ``.namespace`` and
101-
``.localname`` properties hold the respective parts of the tag
102-
name.
103-
104-
You can pass QName objects wherever a tag name is expected. Also,
105-
setting Element text from a QName will resolve the namespace prefix
106-
on assignment and set a qualified text value. This is helpful in XML
107-
languages like SOAP or XML-Schema that use prefixed tag names in
108-
their text content.
99+
See Also
100+
--------
101+
- [API Documentation](https://lxml.de/apidoc/lxml.etree.html#lxml.etree.QName)
109102
"""
110-
@overload
103+
@overload # empty string = exception
104+
@deprecated("Use None instead, empty string would cause exception")
105+
def __init__(
106+
self,
107+
text_or_uri_or_element: Literal[""],
108+
tag: Any = None,
109+
) -> None: ... # Switching to Never causes testsuite problem
110+
@overload # first arg non-empty
111111
def __init__(
112112
self,
113-
text_or_uri_or_element: _TagName | _Element,
114-
tag: _TagName | None = None,
113+
text_or_uri_or_element: str | bytes | QName | _Element,
114+
tag: _TextArg | None = None,
115115
) -> None: ...
116-
@overload
116+
@overload # first arg empty
117117
def __init__(
118118
self,
119119
text_or_uri_or_element: None,
120-
tag: _TagName | _Element,
120+
tag: str | bytes | QName | _Element,
121121
) -> None: ...
122122
@property
123123
def localname(self) -> str: ...
124124
@property
125125
def namespace(self) -> str | None: ...
126126
@property
127-
def text(self) -> str: ...
127+
def text(self) -> str:
128+
"""Holds the qualified name in `{namespace}tagname` notation"""
128129
# Emulate __richcmp__()
129130
def __ge__(self, other: _TagName) -> bool: ...
130131
def __gt__(self, other: _TagName) -> bool: ...

tests/runtime/_testutils/strategy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ def add_ns(ns: str, n: str) -> str:
173173
)
174174

175175

176-
# FIXME: For future test, _e.QName("", "foo") raise exception
177176
def xml_name_arg() -> st.SearchStrategy[str | bytes | bytearray | _e.QName]:
178177
s = xml_name()
179178
qn = s.map(_e.QName)

0 commit comments

Comments
 (0)