Skip to content

Commit

Permalink
fix(mypy): Stub passes type check with 1.10
Browse files Browse the repository at this point in the history
Runtime check still requires mypy 1.11 however
  • Loading branch information
abelcheung committed Oct 25, 2024
1 parent 07e97f6 commit f565104
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ jobs:
fail-fast: false
matrix:
myver:
- 1.10.0
- 1.10.1
- 1.11.0
- 1.11.1
- 1.11.2
- 1.12.0
- 1.12.1
- 1.13.0
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion lxml-stubs/etree/_factory_func.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Element: _ElementFactory
# type annotation attribute is modified.
# OE users need to use E-factory for more flexibility.
@overload
def SubElement(
def SubElement( # type: ignore[overload-overlap]
_parent: ObjectifiedElement,
_tag: _TagName,
/,
Expand Down
4 changes: 2 additions & 2 deletions lxml-stubs/etree/_xslt.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class XSLTExtension(metaclass=abc.ABCMeta):
remove_blank_text: bool = False,
) -> None: ...
@overload
def apply_templates( # pyright: ignore[reportOverlappingOverload]
def apply_templates( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
self,
context: Any,
node: Any,
Expand Down Expand Up @@ -269,7 +269,7 @@ class XSLTExtension(metaclass=abc.ABCMeta):
remove_blank_text: bool = False,
) -> None: ...
@overload
def process_children( # pyright: ignore[reportOverlappingOverload]
def process_children( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
self,
context: Any,
output_parent: None = None,
Expand Down
2 changes: 1 addition & 1 deletion lxml-stubs/html/_parse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def document_fromstring(
base_url: str | None = None,
) -> HtmlElement: ...
@overload
def fragments_fromstring( # pyright: ignore[reportOverlappingOverload]
def fragments_fromstring( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
html: _AnyStr,
no_leading_text: Literal[True],
base_url: str | None = None,
Expand Down
4 changes: 2 additions & 2 deletions lxml-stubs/html/html5parser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ def document_fromstring(
# 2 for html (bytes/str)
# 2 for no_leading_text (true/false)
@overload # html=bytes, no_leading_text=true
def fragments_fromstring( # pyright: ignore[reportOverlappingOverload]
def fragments_fromstring( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
html: bytes,
no_leading_text: Literal[True],
guess_charset: bool | None = None,
parser: HTMLParser | None = None,
) -> list[_Element]: ...
@overload # html=str, no_leading_text=true
def fragments_fromstring( # pyright: ignore[reportOverlappingOverload]
def fragments_fromstring( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
html: str,
no_leading_text: Literal[True],
guess_charset: None = None,
Expand Down
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ classifiers = [
[project.urls]
homepage = 'https://github.com/abelcheung/types-lxml'

# Although mypy 1.10 itself produce no problem in stub,
# it is basically unusable for real life code that uses lxml,
# not until following improvement is done in 1.11.
# https://mypy.readthedocs.io/en/stable/changelog.html#type-inference-improvements

[project.optional-dependencies]
test = [
'tox ~= 4.0',
'mypy ~= 1.11.0',
'mypy ~= 1.11',
'pyright >= 1.1.351',
'typeguard >= 3.0; python_full_version < "3.12.4"',
'typeguard >= 4.3.0; python_full_version >= "3.12.4"',
Expand Down Expand Up @@ -99,6 +104,7 @@ packages = 'lxml-stubs'
strict = true
show_error_context = true
pretty = true
warn_unused_ignores = false

[tool.ruff]
target-version = "py312"
Expand Down
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

10 changes: 8 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ deps =
commands =
pytest --mypy-ini-file=test-stub/mypy-pytest.ini {posargs:test-stub}

# Although mypy 1.10 itself produce no problem in stub,
# it is basically unusable for real life code that uses lxml,
# not until following improvement is done in 1.11.
# https://mypy.readthedocs.io/en/stable/changelog.html#type-inference-improvements
# So runtime test requires 1.11 instead

[testenv:py{310,311,312}-rt-lxml{49,50,51,52,53},py313-rt-lxml53]
deps =
{[testenv:pyright]deps}
{[testenv:mypy]deps}
mypy == 1.11.2
typeguard == 4.3.0
pytest == 8.3.3
html5lib == 1.1
Expand All @@ -57,7 +63,7 @@ commands =
[testenv:mypy]
deps =
{[common_dep]deps}
mypy == 1.12.0
mypy == 1.10.1
package = skip
commands = mypy {posargs:} lxml-stubs

Expand Down

0 comments on commit f565104

Please sign in to comment.