Skip to content

Fix SubplotSpec alias and _server annotation, declare pandas-stubs #67

Description

@tschm

Subcategory: Type safety (+ dependency hygiene)
Score: type safety 3 → ~6, dependency hygiene 9 → 10

Two of these are genuine latent bugs, not annotation noise. Fixing all three clears the 2 import-untyped, 2 valid-type, 1 index, 1 var-annotated and 2 assignment/attr-defined errors, plus most of the 11 cascading no-any-return errors that exist only because untyped pandas returns Any.

What to change

(a) src/pycharting/data/ingestion.py:20SubplotSpec = pd.Series | np.ndarray | list | dict[str, Any] is an implicit alias, which mypy rejects as a type. Use a PEP 695 alias — valid here since the project requires Python ≥ 3.12:

type SubplotSpec = pd.Series | np.ndarray | list | dict[str, Any]

This also clears the downstream index error at ingestion.py:190 and var-annotated at :192.

(b) src/pycharting/core/lifecycle.py:62self._server = None is unannotated, so mypy infers the attribute type as None, making :131 and :134 errors. Annotate:

self._server: uvicorn.Server | None = None

(c) Add pandas-stubs to a dependency group so import pandas is typed (ingestion.py:15, interface.py:23).

done when

mypy --strict reports no valid-type, import-untyped, assignment, attr-defined, index or var-annotated errors.

Evidence

src/pycharting/data/ingestion.py:34: error: Variable "pycharting.data.ingestion.SubplotSpec" is not valid as a type  [valid-type]
src/pycharting/core/lifecycle.py:131: error: Incompatible types in assignment (expression has type "Server", variable has type "None")  [assignment]

Surfaced by the Rhiza quality gates during the template bump to jebel-quant/rhiza@v1.2.2, which enabled the stricter ruff rule families (ANN, A, BLE, ARG) and TYPECHECKER=both. Gate status at time of filing: make fmt FAIL, make typecheck FAIL, make docs-coverage FAIL, test-layout FAIL; make deptry, make security, make test PASS (154 tests, 100% coverage).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions