Skip to content

Commit

Permalink
feat!: Reflect changes in lxml 5.3.1 and 6.0
Browse files Browse the repository at this point in the history
- More html.builder shorthands
- libxml feature constants
- DTD(external_id=...) fix
- Deprecate some Memdebug methods
  • Loading branch information
abelcheung committed Feb 24, 2025
1 parent 40a94e6 commit 7ceca43
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ lxml49 = ["lxml == 4.9.4"]
lxml50 = ["lxml == 5.0.2"]
lxml51 = ["lxml == 5.1.1"]
lxml52 = ["lxml == 5.2.2"]
lxml53 = ["lxml == 5.3.0"]
lxml53 = ["lxml == 5.3.1"]
dev = [
'tox ~= 4.22',
# microsoft/pyright#9286, microsoft/pyright#9296, microsoft/pyright#9412
Expand Down
2 changes: 2 additions & 0 deletions src/lxml-stubs/etree/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ from ._module_misc import (
CDATA as CDATA,
DEBUG as DEBUG,
ICONV_COMPILED_VERSION as ICONV_COMPILED_VERSION,
LIBXML_COMPILED_FEATURES as LIBXML_COMPILED_FEATURES,
LIBXML_COMPILED_VERSION as LIBXML_COMPILED_VERSION,
LIBXML_FEATURES as LIBXML_FEATURES,
LIBXML_VERSION as LIBXML_VERSION,
LXML_VERSION as LXML_VERSION,
C14NError as C14NError,
Expand Down
4 changes: 3 additions & 1 deletion src/lxml-stubs/etree/_dtd.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ class DTD(_Validator):
@overload
def __init__(self, file: _FileReadSource) -> None: ...
@overload
def __init__(self, file: None = None, *, external_id: bytes) -> None: ...
def __init__( # str only supported since 5.3.1
self, file: None = None, *, external_id: str | bytes | bytearray
) -> None: ...
@property
def name(self) -> str | None: ...
@property
Expand Down
2 changes: 2 additions & 0 deletions src/lxml-stubs/etree/_module_func.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ class _MemDebug:
The current size of the global name dictionary used by libxml2
for the current thread. Each thread has its own dictionary.
"""
@deprecated("Removed since 6.0, due to corresponding removal in libxml2")
def dump(
self, output_file: str | bytes | None = None, byte_count: int | None = None
) -> None:
Expand All @@ -482,6 +483,7 @@ class _MemDebug:
byte_count : int, optional
Limits number of bytes in the dump, default is None (unlimited)
"""
@deprecated("Removed since 6.0, due to corresponding removal in libxml2")
def show(
self, output_file: str | bytes | None = None, block_count: int | None = None
) -> None:
Expand Down
2 changes: 2 additions & 0 deletions src/lxml-stubs/etree/_module_misc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ from ._xmlerror import _BaseErrorLog, _ListErrorLog
DEBUG: int
ICONV_COMPILED_VERSION: tuple[int, int]
LIBXML_VERSION: tuple[int, int, int]
LIBXML_COMPILED_FEATURES: set[str]
LIBXML_COMPILED_VERSION: tuple[int, int, int]
LIBXML_FEATURES: set[str]
LXML_VERSION: tuple[int, int, int, int]
__version__: LiteralString

Expand Down
40 changes: 40 additions & 0 deletions src/lxml-stubs/html/builder.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,44 @@ ACRONYM = E.acronym
ADDRESS = E.address
APPLET = E.applet
AREA = E.area
ARTICLE = E.article
ASIDE = E.aside
AUDIO = E.audio
B = E.b
BASE = E.base
BASEFONT = E.basefont
BDI = E.bdi
BDO = E.bdo
BIG = E.big
BLOCKQUOTE = E.blockquote
BODY = E.body
BR = E.br
BUTTON = E.button
CANVAS = E.canvas
CAPTION = E.caption
CENTER = E.center
CITE = E.cite
CODE = E.code
COL = E.col
COLGROUP = E.colgroup
DATA = E.data
DATALIST = E.datalist
DD = E.dd
DEL = E.__getattr__("del")
DETAILS = E.details
DFN = E.dfn
DIALOG = E.dialog
DIR = E.dir
DIV = E.div
DL = E.dl
DT = E.dt
EM = E.em
EMBED = E.embed
FIELDSET = E.fieldset
FIGCAPTION = E.figcaption
FIGURE = E.figure
FONT = E.font
FOOTER = E.footer
FORM: partial[FormElement]
FRAME = E.frame
FRAMESET = E.frameset
Expand All @@ -54,6 +67,8 @@ H4 = E.h4
H5 = E.h5
H6 = E.h6
HEAD = E.head
HEADER = E.header
HGROUP = E.hgroup
HR = E.hr
HTML = E.html
I = E.i
Expand All @@ -67,43 +82,68 @@ LABEL: partial[LabelElement]
LEGEND = E.legend
LI = E.li
LINK = E.link
MAIN = E.main
MAP = E.map
MARK = E.mark
MARQUEE = E.marquee
MENU = E.menu
META = E.meta
METER = E.meter
NAV = E.nav
NOBR = E.nobr
NOFRAMES = E.noframes
NOSCRIPT = E.noscript
OBJECT = E.object
OL = E.ol
OPTGROUP = E.optgroup
OPTION = E.option
OUTPUT = E.output
P = E.p
PARAM = E.param
PICTURE = E.picture
PORTAL = E.portal
PRE = E.pre
PROGRESS = E.progress
Q = E.q
RB = E.rb
RP = E.rp
RT = E.rt
RTC = E.rtc
RUBY = E.ruby
S = E.s
SAMP = E.samp
SCRIPT = E.script
SEARCH = E.search
SECTION = E.section
SELECT: partial[SelectElement]
SLOT = E.slot
SMALL = E.small
SOURCE = E.source
SPAN = E.span
STRIKE = E.strike
STRONG = E.strong
STYLE = E.style
SUB = E.sub
SUMMARY = E.summary
SUP = E.sup
TABLE = E.table
TBODY = E.tbody
TD = E.td
TEMPLATE = E.template
TEXTAREA: partial[TextareaElement]
TFOOT = E.tfoot
TH = E.th
THEAD = E.thead
TIME = E.time
TITLE = E.title
TR = E.tr
TRACK = E.track
TT = E.tt
U = E.u
UL = E.ul
VAR = E.var
VIDEO = E.video
WBR = E.wbr

# attributes
ATTR = dict
Expand Down
4 changes: 4 additions & 0 deletions tests/runtime/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def test_ver_const(self) -> None:
if hasattr(_e, "ICONV_COMPILED_VERSION"):
reveal_type(_e.ICONV_COMPILED_VERSION)

if _e.LXML_VERSION >= (6, 0):
reveal_type(_e.LIBXML_COMPILED_FEATURES)
reveal_type(_e.LIBXML_FEATURES)

def test_other_const(self) -> None:
reveal_type(_e.DEBUG)
_e.DEBUG = 1
Expand Down
9 changes: 5 additions & 4 deletions tests/static/test-dtd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
- args: filename
- args: file=path
- args: fileio
- args: external_id=dtd_id
- args: external_id=b
- args: external_id=s
main: |
from pathlib import PosixPath
from lxml.etree import DTD
filename: str
path: PosixPath
fileio = open('file', 'r')
dtd_id: bytes
b: bytes
s: str
reveal_type(DTD({{ args }})) # N: Revealed type is "lxml.etree._dtd.DTD"
- case: constructor_noargs
Expand All @@ -24,14 +26,13 @@
from lxml.etree import DTD
dtd = DTD()
# str not supported as of lxml 4.8
- case: constructor_badargs
expect_fail: true
parametrized:
- args: 1
- args: "None, 1"
- args: "None, badarg=b"
- args: "external_id=s"
- args: "external_id=1"
main: |
from lxml.etree import DTD
s: str
Expand Down

0 comments on commit 7ceca43

Please sign in to comment.