Skip to content

Commit 7ceca43

Browse files
committed
feat!: Reflect changes in lxml 5.3.1 and 6.0
- More html.builder shorthands - libxml feature constants - DTD(external_id=...) fix - Deprecate some Memdebug methods
1 parent 40a94e6 commit 7ceca43

File tree

8 files changed

+59
-6
lines changed

8 files changed

+59
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ lxml49 = ["lxml == 4.9.4"]
7272
lxml50 = ["lxml == 5.0.2"]
7373
lxml51 = ["lxml == 5.1.1"]
7474
lxml52 = ["lxml == 5.2.2"]
75-
lxml53 = ["lxml == 5.3.0"]
75+
lxml53 = ["lxml == 5.3.1"]
7676
dev = [
7777
'tox ~= 4.22',
7878
# microsoft/pyright#9286, microsoft/pyright#9296, microsoft/pyright#9412

src/lxml-stubs/etree/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ from ._module_misc import (
6262
CDATA as CDATA,
6363
DEBUG as DEBUG,
6464
ICONV_COMPILED_VERSION as ICONV_COMPILED_VERSION,
65+
LIBXML_COMPILED_FEATURES as LIBXML_COMPILED_FEATURES,
6566
LIBXML_COMPILED_VERSION as LIBXML_COMPILED_VERSION,
67+
LIBXML_FEATURES as LIBXML_FEATURES,
6668
LIBXML_VERSION as LIBXML_VERSION,
6769
LXML_VERSION as LXML_VERSION,
6870
C14NError as C14NError,

src/lxml-stubs/etree/_dtd.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ class DTD(_Validator):
8585
@overload
8686
def __init__(self, file: _FileReadSource) -> None: ...
8787
@overload
88-
def __init__(self, file: None = None, *, external_id: bytes) -> None: ...
88+
def __init__( # str only supported since 5.3.1
89+
self, file: None = None, *, external_id: str | bytes | bytearray
90+
) -> None: ...
8991
@property
9092
def name(self) -> str | None: ...
9193
@property

src/lxml-stubs/etree/_module_func.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ class _MemDebug:
470470
The current size of the global name dictionary used by libxml2
471471
for the current thread. Each thread has its own dictionary.
472472
"""
473+
@deprecated("Removed since 6.0, due to corresponding removal in libxml2")
473474
def dump(
474475
self, output_file: str | bytes | None = None, byte_count: int | None = None
475476
) -> None:
@@ -482,6 +483,7 @@ class _MemDebug:
482483
byte_count : int, optional
483484
Limits number of bytes in the dump, default is None (unlimited)
484485
"""
486+
@deprecated("Removed since 6.0, due to corresponding removal in libxml2")
485487
def show(
486488
self, output_file: str | bytes | None = None, block_count: int | None = None
487489
) -> None:

src/lxml-stubs/etree/_module_misc.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ from ._xmlerror import _BaseErrorLog, _ListErrorLog
2424
DEBUG: int
2525
ICONV_COMPILED_VERSION: tuple[int, int]
2626
LIBXML_VERSION: tuple[int, int, int]
27+
LIBXML_COMPILED_FEATURES: set[str]
2728
LIBXML_COMPILED_VERSION: tuple[int, int, int]
29+
LIBXML_FEATURES: set[str]
2830
LXML_VERSION: tuple[int, int, int, int]
2931
__version__: LiteralString
3032

src/lxml-stubs/html/builder.pyi

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,44 @@ ACRONYM = E.acronym
1919
ADDRESS = E.address
2020
APPLET = E.applet
2121
AREA = E.area
22+
ARTICLE = E.article
23+
ASIDE = E.aside
24+
AUDIO = E.audio
2225
B = E.b
2326
BASE = E.base
2427
BASEFONT = E.basefont
28+
BDI = E.bdi
2529
BDO = E.bdo
2630
BIG = E.big
2731
BLOCKQUOTE = E.blockquote
2832
BODY = E.body
2933
BR = E.br
3034
BUTTON = E.button
35+
CANVAS = E.canvas
3136
CAPTION = E.caption
3237
CENTER = E.center
3338
CITE = E.cite
3439
CODE = E.code
3540
COL = E.col
3641
COLGROUP = E.colgroup
42+
DATA = E.data
43+
DATALIST = E.datalist
3744
DD = E.dd
3845
DEL = E.__getattr__("del")
46+
DETAILS = E.details
3947
DFN = E.dfn
48+
DIALOG = E.dialog
4049
DIR = E.dir
4150
DIV = E.div
4251
DL = E.dl
4352
DT = E.dt
4453
EM = E.em
54+
EMBED = E.embed
4555
FIELDSET = E.fieldset
56+
FIGCAPTION = E.figcaption
57+
FIGURE = E.figure
4658
FONT = E.font
59+
FOOTER = E.footer
4760
FORM: partial[FormElement]
4861
FRAME = E.frame
4962
FRAMESET = E.frameset
@@ -54,6 +67,8 @@ H4 = E.h4
5467
H5 = E.h5
5568
H6 = E.h6
5669
HEAD = E.head
70+
HEADER = E.header
71+
HGROUP = E.hgroup
5772
HR = E.hr
5873
HTML = E.html
5974
I = E.i
@@ -67,43 +82,68 @@ LABEL: partial[LabelElement]
6782
LEGEND = E.legend
6883
LI = E.li
6984
LINK = E.link
85+
MAIN = E.main
7086
MAP = E.map
87+
MARK = E.mark
88+
MARQUEE = E.marquee
7189
MENU = E.menu
7290
META = E.meta
91+
METER = E.meter
92+
NAV = E.nav
93+
NOBR = E.nobr
7394
NOFRAMES = E.noframes
7495
NOSCRIPT = E.noscript
7596
OBJECT = E.object
7697
OL = E.ol
7798
OPTGROUP = E.optgroup
7899
OPTION = E.option
100+
OUTPUT = E.output
79101
P = E.p
80102
PARAM = E.param
103+
PICTURE = E.picture
104+
PORTAL = E.portal
81105
PRE = E.pre
106+
PROGRESS = E.progress
82107
Q = E.q
108+
RB = E.rb
109+
RP = E.rp
110+
RT = E.rt
111+
RTC = E.rtc
112+
RUBY = E.ruby
83113
S = E.s
84114
SAMP = E.samp
85115
SCRIPT = E.script
116+
SEARCH = E.search
117+
SECTION = E.section
86118
SELECT: partial[SelectElement]
119+
SLOT = E.slot
87120
SMALL = E.small
121+
SOURCE = E.source
88122
SPAN = E.span
89123
STRIKE = E.strike
90124
STRONG = E.strong
91125
STYLE = E.style
92126
SUB = E.sub
127+
SUMMARY = E.summary
93128
SUP = E.sup
94129
TABLE = E.table
95130
TBODY = E.tbody
96131
TD = E.td
132+
TEMPLATE = E.template
97133
TEXTAREA: partial[TextareaElement]
98134
TFOOT = E.tfoot
99135
TH = E.th
100136
THEAD = E.thead
137+
TIME = E.time
101138
TITLE = E.title
102139
TR = E.tr
140+
TRACK = E.track
103141
TT = E.tt
104142
U = E.u
105143
UL = E.ul
106144
VAR = E.var
145+
VIDEO = E.video
146+
WBR = E.wbr
107147

108148
# attributes
109149
ATTR = dict

tests/runtime/test_constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def test_ver_const(self) -> None:
2727
if hasattr(_e, "ICONV_COMPILED_VERSION"):
2828
reveal_type(_e.ICONV_COMPILED_VERSION)
2929

30+
if _e.LXML_VERSION >= (6, 0):
31+
reveal_type(_e.LIBXML_COMPILED_FEATURES)
32+
reveal_type(_e.LIBXML_FEATURES)
33+
3034
def test_other_const(self) -> None:
3135
reveal_type(_e.DEBUG)
3236
_e.DEBUG = 1

tests/static/test-dtd.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
- args: filename
99
- args: file=path
1010
- args: fileio
11-
- args: external_id=dtd_id
11+
- args: external_id=b
12+
- args: external_id=s
1213
main: |
1314
from pathlib import PosixPath
1415
from lxml.etree import DTD
1516
filename: str
1617
path: PosixPath
1718
fileio = open('file', 'r')
18-
dtd_id: bytes
19+
b: bytes
20+
s: str
1921
reveal_type(DTD({{ args }})) # N: Revealed type is "lxml.etree._dtd.DTD"
2022
2123
- case: constructor_noargs
@@ -24,14 +26,13 @@
2426
from lxml.etree import DTD
2527
dtd = DTD()
2628
27-
# str not supported as of lxml 4.8
2829
- case: constructor_badargs
2930
expect_fail: true
3031
parametrized:
3132
- args: 1
3233
- args: "None, 1"
3334
- args: "None, badarg=b"
34-
- args: "external_id=s"
35+
- args: "external_id=1"
3536
main: |
3637
from lxml.etree import DTD
3738
s: str

0 commit comments

Comments
 (0)