Releases: abelcheung/types-lxml
Releases · abelcheung/types-lxml
2024.12.13
Breaking changes and features
bytearray
accepted as tag names, attribute names and attribute values- Related change: create
_TextArg
type alias to slowly replace existing_AnyStr
(#71)
- Related change: create
- Warn IDE users via
warnings.deprecated
about exception upon certain argument combinations in HTML link functions
Bug fixes
- Property deleter missing for HTML elements (#73)
etree.strip_attributes()
supportbytes
andQName
as input- Completion of #64 for remaining known cases
- Corrected link replacement function return type in
html.rewrite_links()
etree.canonicalize()
shouldn't acceptbytes
as input
Tests related
- Use
hypothesis
for extensive tests on function arguments, currently used in_Attrib
and HTML link function tests (#75) reveal_type()
injector has been split into its own project and pulled via dependency
Internal changes
- Folder structure changes for the whole repository (#70)
- Remove
_HANDLE_FAILURES
type alias and show values directly to users - Rename type-only protocol
SupportsLaxedItems
toSupportsLaxItems
Full Changelog: 2024.11.08...2024.12.13
2024.11.08
Breaking and important changes
pyright
users (and IDE that can make use ofpyright
) will see warning if a single string is supplied where collection of string is expected (tuple
,set
,list
etc). In terms of typing, a singlestr
itself is valid as aSequence
, so type checkers normally would not raise alarm when usingstr
in such function parameters, but can induce unexpected runtime behavior. (#64)_ElementTree.write()
,etree.fromstringlist()
,etree.tostring()
,html.soupparser.fromstring()
,html.soupparser.parse()
- It is possible to verify release files indeed come from GitHub and not maliciously altered. See Release file attestation for detail.
- Runtime tests support comparing with
mypy
results, therefore officially making static stub tests obsolete
Bug fixes
- Element tag names, attribute names and attribute values support
bytearray
. This is discovered viahypothesis
testing, which is intended to be utilized in next release - Compatibility with
pyright ⩾ 1.1.378
, which imposes additional overload warning foretree.iterparse()
- Use relative import in
lxml.ElementInclude
, otherwisemypy
triggers--install-type
behavior. ObjectifiedElement
__getitem()__
and__setitem()__
should acceptstr
as key, which behaves mostly like__getattr__()
and__setattr__()
. That means,elem["foo"]
is equivalent toelem.foo
for non-repeating subelements.
fixes for etree submodule
_Element.tag
property is not just astr
. It isstr
after initial document or string parsing, but can be set manually to any type supported by tag name and returns the same object.- When
QName
is initialized with first argument set toNone
,_Element
can be used as second argument (which is promoted to first argument in implementation) - Relax single argument usage in
_Element.iter*()
method family, doesn't needtag=
keyword when argument isNone
FunctionNamespace()
should generate an_XPathFunctionNamespaceRegistry
object, not its superclass- For decorator usage of
_XPathFunctionNamespaceRegistry
and_ClassNamespaceRegistry
, decorator signature included an extraneous argument, though it doesn't affect any existing correct usage. indent()
first parameter has wrong name
fixes for html submodule
soupparser.parse()
should acceptpathlib.Path
object as input.value
property ofSelectElement
can't be set tobytes
.action
property ofFormElement
can have a value ofNone
, and can be set toNone
. They have different meanings though.
Small and internal changes
- Declare python 3.13 support and perform CI tests.
- Separation of
pyright
andmypy
ignore comments: in previous releases# type: ignore[code]
was enabled inpyright
settings. Now it only uses# pyright: ignore[code]
somypy
comment won't affectpyright
behavior. - Add
._name
property tohtml.FormElement
for form name - Eliminate
typing.TypeAlias
usage (declared obsolete, and we can do without it)
Test related changes
- Stub tests migration to runtime:
- Most of remaining
etree._Element
methods, now only.makeelement()
and.xpath()
left in stub test
- Most of remaining
- Runtime test additions:
ElementNamespaceClassLookup()
tox
config migrated topyproject.toml
, thus requiringtox ⩾ 4.22
- Runtime tests are now executed within
test-rt
folder due to python/mypy#8400 - Some tests need to be performed conditionally when multi-subclass patch is applied
- Some tests or syntaxes need to be turned off to cope with
mypy
deficiencies - Usage of Rust-based
uv
as well as relatedtox
plugin to speed up test environment recreation - Don't force users installing
tox-gh-actions
when checkout out repository, it is only useful for GitHub workflows
Docstring additions
etree
submodule:parse()
,fromstringlist()
,tostring()
,indent()
,iselement()
,adopt_external_document()
,DocInfo
properties,QName
,CData
, some exception classeshtml.soupparser
submodule:fromstring()
,parse()
,convert_tree()
2024.09.16
Bug fix and small changes
- Namespace argument in Elementpath methods should allow
None
(#60 thanks to @cukiernick)
Internal changes
- Perform runtime tests against
lxml 5.3
2024.08.07
Breaking changes
- Multiple builds available, with the alternative build enhancing multiple XML subclassing scenario. See relevant README section for detail. Thanks to @scanny for the driving force behind #51.
Mypy
1.11 required, which introduced backward incompatible@typing.overload
changes.lxml.html.clean
stub depreated,lxml 5.2.0
completely removes the submodule due to multiple security issues. Corresponding code and type definitions are split into a new independent repo.
Features
- (#56) Replace
typing.TypeGuard
withtyping.TypeIs
- Use callback protocol for more precise element and
ElementMaker
factory function typing lxml.etree.ICONV_COMPILED_VERSION
exported since5.2.2
- Special handling for
ObjectifiedElement
andHTMLElement
inlxml.cssselect.CSSSelector
and variouscssselect()
methods html.builder
shorthands return more precise element type for certain HTML elements. For example,html.builder.LABEL()
, corresponding to<LABEL>
tag, yieldsLabelElement
.- More precise
etree.Extension()
annotation depending on supplied namespace - Stricter namespace argument type in
_Element
ElementPath methods - For
lxml.builder.ElementMaker
class:- Provide better hint in
__call__()
argument - Accepts namespace tuple in
nsmap
argument - Export private properties
- Provide better hint in
- For
lxml.sax
module:- Export private properties in various classes
- Explicitly list all inherited methods in
ElementTreeContentHandler
class, as method arguments names are different from superclass ones
- Alert
etree.HTMLParser
users to remove deprecatedstrip_cdata
argument
Bug fix and small changes
- Some
_Element
related input arguments fixed to usetyping.Sequence
instead ofInterable
, as_Element
is already anIterable
itself. Supplying_Element
where a properIterable
is expected would cause problem. - Similar situation arises for
str
orbyte
in tag selector argument; usetyping.Collection
to alert user more clearly. None
can't be used asetree.strip_*()
argument- Some
etree.DocInfo
read-only properties can't beNone
- Fix
etree.Resolver
method return types - Avoid exception raising arg combinations in
html.html5parser.HTMLParser
Internal changes
- The usual static stub to runtime test migration:
- Part of basic
_Element
tests and itsfind*()
methods - More extensive
_Attrib
tests
- Part of basic
- Use
ruff
to replaceblack
andisort
as code formatter - Migrate stub tests to support
pytest-mypy-plugins ⩾ 2.0
- Use
pdm-backend
as build backend due to its more versatile versioning support
2024.04.14
Breaking changes
Mypy
1.9 is required, dropping 1.5 support. 1.6 - 1.8 was never supported.lxml.ElementInclude
completely reworked
Features
- PEP 696 support, simplifying usage of some subscripted types (#42)
- As a convenient side effect,
lxml.html
parser constructor signatures can be removed
- As a convenient side effect,
- All annotations do provide default values in their signatures now instead of
...
Bug fix and small changes
- Type of
_Comment.text
property (and those of similar elements) is alwaysstr
(#46, thanks to @eemeli) - Tag selector argument in element iterator methods should support keyword with a single tag (#45, thanks to @eemeli)
html.fragments_fromstring()
should receive same fix ashtml.html5parser.fragments_fromstring()
do (#43, thanks to @Wuestengecko)@overload
foretree.SubElement()
on handling ofHtmlElement
andObjectifiedElement
- Some exported constants were missing from
lxml.ElementInclude
stub html.soupparser
module functions return type depends onmakeelement
argument- Keyword arguments in
html.soupparser
module functions are explicitly listed now (instead of generic**kwargs
before) - The 2 arguments in
html.diff.html_annotate()
should align their annotation types html.submit_form()
return type depends on the result ofopen_http
function argument- Add missing exported variable for
lxml.isoschematron
- Uppercase variants of output method arguments ("HTML", "TEXT", "XML") were dropped
Internal changes
- Usual runtime test additions:
lxml.html.soupparser
,lxml.ElementInclude
, various exported constants - Runtime tests also do test against lxml 5.2
2024.03.27
Breaking change
- Requires
cssselect ⩾ 1.2
for annotation inlxml.cssselect
, sincecssselect
is now inline annotated.
Bug fix and small changes
- Compatibility with
pyright ⩾ 1.1.353
- In
etree.clean_*
functions, first argument (the Element or ElementTree to be processed) must be strictly positional etree._LogEntry.filename
property is never empty, as it uses the value<string>
as fallbacketree._BaseErrorLog.receive()
argument name was wrong- Self brewed
SupportsReadClose
protocol dropped, replacing with more standardizedSupportsRead
html.html5parser.parse()
should support data stream as inputhtml.html5parser.fragments_fromstring()
return type is dependent onno_leading_text
argumentencoding
arguments in various methods / functions used to only support ASCII and UTF-8 as byte encodings, now the restriction is lifted- Place some
typing
usage under python version check (if sys.version_info >= (3, x)
) etree.PyErrorLog
constructor shouldn't accept 2 logger arguments simultaneouslyetree.PyErrorLog.level_map
property reverted to vanilla type (int
) instead of our fakeenum
Internal changes
2024.02.09
Bug fix and small changes
- Add back
HtmlProcessingInstruction
element (#28, thanks to @eliotwrobson) - Silence
pyright
⩾ 1.1.345 warning on overriding read-write property with read-only one (ObjectifyElement.text
)
Documentation
mypy
⩾ 1.6 does not support PEP702, thus shouldn't be used withtypes-lxml
Internal changes
- Stub test suite uses
mypy
1.5.x now
2023.10.21
Bug Fix
- Types for emitted events and values in
iterparse()
were not optimal (issue #19, thanks to @Daverball) - Most
html
link and clean functions should be unable to processElementTree
, exceptCleaner.clean_html()
Feature
- Completed following modules, thus really having
lxml
fully covered (sans a few submodules that will never be implemented):lxml.html.diff
lxml.ElementInclude
- Declares support for Python 3.12
- Update for upcoming
lxml
5.0Schematron
constructor arguments- Some obsolete functions removed
Internal change
- Start implementing runtime type checks and compare with static type checker results, utilizing
typeguard
andpyright
- Use
setuptools_scm
in place ofpdm-backend
as package build backend
Here is the list of change since last release. Besides, please check out release notes for previous release as well, since it contains substantial changes.
2023.3.28
The list of changes since last release is huge, be it visible by users or not.
Breaking changes
- Class inheritance of
html.HtmlComment
and friends have changed to deviate from source code. Now they are 'thought' to inherit fromhtml.HtmlElement
within stubs, like the XMLetree._Element
counterpart. Refer to wiki document on how and why this change is done. - Shelved custom parser target support (custom parser target is used when initiating XML / HTML parsers with
target=
argument), as current python typing system is deemed insufficient to get it working without plugins. - Stub package only depends on other stub packages, following behavior of typeshed distributed stubs. This means
lxml
is no longer pulled in when installingtypes-lxml
. etree.SmartStr
reverted back to its original class nameetree._ErrorLog
is now made a function that generatesetree._ListErrorLog
(despite the fact that it is a class in source code), according to actual created instance type
Significant changes / completion
- Completed following submodules and parts, thus removing the partial status of
types-lxml
package:lxml.etree
proper:- XSLT related classes / functions
- XML:ID support
- External document and URI resolving
- XInclude support
- XPath and XSLT extension function registry
- Error log and reporting, along with numerous bug fixes
-
etree.iterparse
andetree.iterwalk
- Various
ElementClassLookup
types
-
lxml.objectify
- Includes all
DataElement
subtypes and type annotation support
- Includes all
-
lxml.isoschematron
- When subclassing XML elements, now most of its methods can be inherited without overriding output element type.
Smaller changes
- More extensive usage of Python 3.9-3.11 typing features, this is possible since
types-lxml
is external stub package and doesn't affect source code. Such as: - Both
mypy
andpyright
type checkers have strict mode turned on when verifying stub source _Element.sourceline
property becomes read-only- Re-added most deprecated methods in various places, with help from provisional PEP 702 support (
@deprecated
) inpyright
- Incorporate more docstring from official
lxml
classes, in case IDEs can display them in user interface. - Force
_XPathEvaluatorBase
subclasses to make__call__
available, by explicitly declaring it as abstract method within_XPathEvaluatorBase
- Removal of
http.open_http_urllib
, which is only intended as a fallback callback function forhtml.submit_form()
without user intervention libxml2
error constants become integerenum
in stub- Warn userland usage of dummy
etree.PyErrorLog.copy()
, because it is only intended for smoother internallxml
error handling.
Bug fixes
- File reading source (used in
file=
argument inparse()
and friends) requirement relaxed html.(X)HtmlParser
__init__
was missing some arguments- Convert
iter*
methods of Elements and some tag cleanup functions into@overload
, to better reflect its original intended arguments usage etree.ElementBase
and similar public base element classes lacked__init__
- Setting of
etree.DocInfo
text properties now acceptsbytes
name=
argument ofhtml.HtmlElementClassLookup()
doesn't acceptNone
- Concerning
_Comment
,_Entity
,_ProcessingInstruction
, and their subclasses.tag
attribute now returns correct value (the basic etree element factory function)- Users will be warned if they use these elements like normal XML
_Element
do, such as treating them as parent elements and insert children element into them
2023.02.11
User visible change since previous release:
- Add types for XML canonicalization function/class and incremental generation context managers