Skip to content

Commit 85df932

Browse files
authored
chore: check in a Pyright config and lxml type stubs (#17)
1 parent 8b88d55 commit 85df932

4 files changed

Lines changed: 33 additions & 5 deletions

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ dev = [
6363
"respx>=0.21",
6464
"ruff>=0.7",
6565
"mypy>=1.13",
66+
"lxml-stubs>=0.5.1",
6667
]
6768

6869
[tool.ruff]
@@ -90,10 +91,6 @@ init_typed = false
9091
warn_required_dynamic_outputs = true
9192
warn_untyped_fields = true
9293

93-
[[tool.mypy.overrides]]
94-
module = ["lxml.*"]
95-
ignore_missing_imports = true
96-
9794
[tool.pytest.ini_options]
9895
minversion = "8.0"
9996
testpaths = ["tests"]

‎pyrightconfig.json‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"//": "Pyright/Pylance config. Without this, a fresh clone reports ~78 phantom",
3+
"//2": "'could not be resolved' errors for httpx/pydantic/lxml/cryptography,",
4+
"//3": "because Pyright does not find .venv on its own. Checked in so the IDE",
5+
"//4": "and the command line agree for everyone.",
6+
"venvPath": ".",
7+
"venv": ".venv",
8+
"include": ["src", "tests", "scripts"],
9+
"exclude": ["**/__pycache__", ".venv", "dist"],
10+
"pythonVersion": "3.11",
11+
"typeCheckingMode": "standard",
12+
"reportMissingTypeStubs": false
13+
}

‎src/myinvois/ubl/builders/xml.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,15 @@ def build_xml(self) -> str:
7070

7171
# Root element owns all four xmlns declarations. lxml uses ``None`` as
7272
# the nsmap key for the default namespace so the root tag is unprefixed.
73+
#
74+
# `lxml-stubs` types nsmap as Mapping[str, str], which cannot express
75+
# that None key -- a gap in the stubs, not in lxml: passing None is the
76+
# documented way to declare a default namespace, and the golden
77+
# fixtures depend on it emitting `<Invoice xmlns="...">`. Suppressed
78+
# narrowly rather than widening the annotation, which would hide real
79+
# misuse of this call.
7380
nsmap = {None: ns_url, "cac": _NS_CAC, "cbc": _NS_CBC, "ext": _NS_EXT}
74-
root = etree.Element(f"{{{ns_url}}}{tag_name}", nsmap=nsmap)
81+
root = etree.Element(f"{{{ns_url}}}{tag_name}", nsmap=nsmap) # type: ignore[arg-type]
7582

7683
content = self._content_dump()
7784
self._stamp_currency(content, self._document_currency_code())

‎uv.lock‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)