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
Add tests/ to mypy scope; fix real type gaps it surfaces (#250)
* Add tests/ to mypy scope and fix the type gaps it surfaces
Widens a handful of source annotations that were too narrow for
already-supported behavior (str|None config scalars, list[str]
accepted by is_prefix/is_conjunction/is_suffix and __setitem__,
bytes accepted by add_with_encoding), and adds targeted type:
ignore comments on the lines that deliberately violate the type
contract to assert a TypeError/behavior, matching the existing
convention in test_constants.py.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* Fix AGENTS.md staleness introduced by this PR's mypy scope change
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* Explain why empty_attribute_default's type:ignores exist
Per code review: the AGENTS.md guidance added in this branch says to
widen an annotation rather than ignore when runtime already supports
the wider type, but empty_attribute_default is that exact case and
was left un-widened. Document the deliberate scope decision (avoids
cascading into ~8 public str-typed properties) at each ignore site
instead of leaving it unexplained.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: AGENTS.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,8 +23,8 @@ uv run pytest # --doctest-modules is set in pyproject.toml, so doctests run aut
23
23
uv run pytest tests/test_python_api.py
24
24
uv run pytest tests/test_python_api.py::HumanNamePythonTests::test_utf8
25
25
26
-
# Type check
27
-
uv run mypy nameparser/
26
+
# Type check (covers nameparser/ and tests/, per pyproject.toml's [tool.mypy] packages)
27
+
uv run mypy
28
28
29
29
# Lint
30
30
uv run ruff check nameparser/
@@ -162,7 +162,7 @@ Don't use the bare `python3 -m doctest <file>.rst` CLI (no `optionflags`) to che
162
162
163
163
`Constants` class attributes (e.g. `patronymic_name_order`, `middle_name_as_last`) document behavior with a bare string literal placed right after the assignment — Sphinx's attribute-docstring convention. That string never becomes a real `__doc__`, so `--doctest-modules` (which walks `__doc__` attributes) never sees any `.. doctest::` examples inside it — this let a stale example slip through CI once (`middle_name_as_last`, #133). `tests/test_config_attribute_docstrings.py` (#195) closes that gap: it parses `nameparser/config/__init__.py` with `ast` to recover those literals and runs any doctest examples through `doctest.DocTestParser`/`DocTestRunner` explicitly, so `pytest -q` now exercises them too. When adding or editing a `.. doctest::` example in a `Constants` attribute's bare-string docstring, this is the mechanism that actually runs it — don't assume `--doctest-modules` covers it.
164
164
165
-
**`uv run mypy nameparser/` intentionally excludes `tests/`** (`pyproject.toml`'s `[tool.mypy] packages = ["nameparser"]`) — if you run mypy against `tests/` too you'll see ~30 pre-existing errors; don't treat them as a regression. Most are intentionally wrong-typed inputs verifying the code rejects them, or `Constants` attribute assignments the config type hints don't capture.
165
+
**`uv run mypy` covers `tests/` too** (`pyproject.toml`'s `[tool.mypy] packages = ["nameparser", "tests"]`, PR #250) — a test that deliberately passes an off-contract value to assert a `TypeError`/`ValueError`, or exercises a documented falsy-disables-the-feature toggle (e.g. `regexes.emoji = False`), needs a `# type: ignore[code]` comment on that line rather than a signature change. Before reaching for an ignore, check whether the "error" is really a source annotation that hasn't caught up with already-supported runtime behavior (e.g. `is_prefix`/`is_conjunction`/`is_suffix` accepting `list[str]`, `add_with_encoding` accepting `bytes`) — widen the annotation instead in that case.
166
166
167
167
**`initials_separator` is intra-group only** — it controls the joiner between consecutive initials *within* a name group (e.g. two middle names in `middle_list`). Spaces *between* groups come from `initials_format`. To fully concatenate initials you need both `initials_separator=""` and `initials_format="{first}{middle}{last}"`.
0 commit comments