You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-38Lines changed: 38 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,8 @@
6
6
## Important note
7
7
8
8
- Upcoming release:
9
-
- Support for [`ty` type checker from Astral](https://docs.astral.sh/ty/) in progress
9
+
- Support for [`pyrefly` type checker](https://pyrefly.org/)
10
+
- New `mypy` plugin that mimics [`XMLParser.set_element_class_lookup()` behavior](https://github.com/abelcheung/types-lxml/wiki/Using-specialised-class-directly#no-automatic-change-of-subscript)
10
11
11
12
- Since `2025.11.25`:
12
13
-[PEP 800 support](https://peps.python.org/pep-0800/), thus only compatible with newest type checkers as of Oct 2025
@@ -19,52 +20,32 @@
19
20
-`BeautifulSoup4` package is added as dependency to utilise its inline annotation, thus dropping `types-beautifulsoup4` dependency.
20
21
- Fixes compatibility with older versions of type checkers, as well as `mypy` 1.14+.
21
22
22
-
- Since `2025.02.24`:
23
-
- Add [`basedpyright`](https://github.com/DetachHead/basedpyright) type checker support (an enhanced fork of `pyright`)
24
-
25
-
- Since `2024.11.08`:
26
-
-`pyright` and `vscode` users will [receive warnings](#warnings-for-exception-and-wrong-code) if certain `lxml` API usage would result in exception or undesirable runtime behavior.
27
-
- It is possible to [verify release files](#release-file-attestation) indeed come from GitHub and not maliciously altered.
28
23
29
24
## Introduction
30
25
31
-
This repository contains [external type annotations](https://peps.python.org/pep-0561/) for [`lxml`](http://lxml.de/). It can be used by [type-checking tools](#goal---support-multiple-type-checkers) to check code that uses `lxml`, or used within IDEs like [VSCode](https://code.visualstudio.com/) to facilitate development.
26
+
This repository contains [external type annotations](https://peps.python.org/pep-0561/) for [`lxml`](http://lxml.de/). It can be used by [type-checking tools](#goal---support-multiple-type-checkers) to check code that uses `lxml`, or used within IDEs like [Visual Studio Code](https://code.visualstudio.com/) to facilitate development.
32
27
33
28
## Goal ① : Completion
34
29
35
-
Now the coverage of `lxml` submodules is complete (unless intentionally rejected, see further below), thus no more [considered as `partial`](https://peps.python.org/pep-0561/#partial-stub-packages):
36
-
-[x]`lxml.etree`
37
-
-[x]`lxml.html`
38
-
-[x]`lxml.html.builder`
39
-
-[x]`lxml.html.clean` (already removed in lxml 5.2.0, this project will follow suite in future)
40
-
-[x]`lxml.html.diff`
41
-
-[x]`lxml.html.html5parser`
42
-
-[x]`lxml.html.soupparser`
43
-
-[x]`lxml.isoschematron`
44
-
-[x]`lxml.objectify`
45
-
-[x]`lxml.builder`
46
-
-[x]`lxml.cssselect`
47
-
-[x]`lxml.sax`
48
-
-[x]`lxml.ElementInclude`
49
-
50
-
Following submodules will not be implemented due to irrelevance to type checking or other reasons:
30
+
Implementation is complete since 1Q 2003, thus no more [considered as `partial`](https://peps.python.org/pep-0561/#partial-stub-packages). Following submodules intentionally not implemented due to irrelevance to type checking or other reasons:
51
31
52
32
-`lxml.etree.Schematron` (obsolete and superseded by `lxml.isoschematron`)
53
-
-`lxml.usedoctest`
54
-
-`lxml.html.usedoctest`
33
+
-`lxml.usedoctest` (for testing only)
34
+
-`lxml.html.usedoctest` (for testing only)
55
35
-`lxml.html.formfill` (shouldn't have existed, this would belong to HTTP libraries like `requests` or `httpx`)
56
36
57
-
Check out [project page](https://github.com/abelcheung/types-lxml/projects) for future plans and progress.
58
-
59
37
## Goal ② : Support multiple type checkers
60
38
61
39
Currently the annotations are validated for following type checkers:
62
40
63
-
-[`basedpyright`](https://github.com/DetachHead/basedpyright), version 1.31.6 or above
64
-
-[`pyright`](https://github.com/microsoft/pyright), version 1.1.406 or above
65
-
-[`mypy`](https://github.com/python/mypy), version 1.18.1 or above
`pyright` and `basedpyright` are recommended for their greater flexibilityand early adoption of newer type checking features. In the future, there is plan to bring even more type checker support.
48
+
`pyright` and `basedpyright` are recommended for their greater flexibility, maturity and early adoption of newer type checking features. In the future, there is plan to bring even more type checker support (such as `ty` or `zuban`).
68
49
69
50
## Goal ③: Review and test suite
70
51
@@ -83,15 +64,17 @@ This package tries to bring type annotation specific docstrings for some classes
83
64
84
65
#### Warnings for exception and wrong code
85
66
86
-
`pyright` (and therefore `vscode`) users receive additional benefit of being forewarned when their lxml code will likely cause undesirable runtime behavior or outright exception.
`pyright` and `basedpyright` users receive additional benefit of being forewarned when their lxml code will likely cause undesirable runtime behavior or outright exception.
87
70
-[#64](https://github.com/abelcheung/types-lxml/issues/64) covers one such example where such warnings are warrented.
88
71
- Another example is `html.html5parser` submodule functions causing exception when `str` input and `guess_charset` parameter are used together.
89
72
73
+
Similarly their corresponding Visual Studio Code extensions would display visual cue when such problematic usage is encountered, as shown in above screenshot.
74
+
90
75
> [!NOTE]
91
76
> This feature makes use of [`@deprecated` decorator](https://typing.python.org/en/latest/spec/directives.html#deprecated) from Python 3.13. `mypy` disables such warnings by default, and need to be [turned on explicitly](https://mypy.readthedocs.io/en/stable/error_code_list2.html#check-that-imported-or-used-feature-is-deprecated-deprecated).
Current annotations are geared towards convenience for programmers' convenience instead of absolute logical 'correctness'. The [deviation of class inheritance](https://github.com/abelcheung/types-lxml/wiki/Element-inheritance-change) for `HtmlComment` and friends is one prominent example.
@@ -107,10 +90,27 @@ The normal choice for most people is to fetch package from PyPI, like:
107
90
108
91
In the unlikely case PyPI is down, one can directly download wheel from [latest release in GitHub](https://github.com/abelcheung/types-lxml/releases/latest), and then perform installation as local file.
109
92
110
-
As convenience, it is possible to pull type checker directly [with extras](https://peps.python.org/pep-0508/#extras):
93
+
As convenience, it is possible to [pull development related packages](https://peps.python.org/pep-0508/#extras). This helps when you want to submit PR on bugs or features:
94
+
95
+
uv pip install -U types-lxml[dev]
96
+
pip install -U types-lxml[dev]
111
97
112
-
uv pip install -U types-lxml[pyright]
113
-
pip install -U types-lxml[mypy]
98
+
The stub package supports all Python versions since 3.9. But if you want to create PR and test your changes, Python 3.10 is needed.
99
+
100
+
### Mypy plugin usage
101
+
102
+
Mypy plugin bundled with this stub package needs to be explicitly turned on from config. Add these two lines under `[mypy]` global section if you're using INI file:
103
+
104
+
```ini
105
+
plugins =
106
+
mypy_plugin_lxml.main
107
+
```
108
+
109
+
Alternatively, add this under `[tool.mypy]` section for `pyproject.toml`:
0 commit comments