Skip to content

chore(typing): silence the pyright advisory output (31 → 0 errors) - #4

Merged
ancongui merged 2 commits into
mainfrom
chore/clean-pyright-advisory
May 14, 2026
Merged

ancongui merged 2 commits into
mainfrom
chore/clean-pyright-advisory

Conversation

@ancongui

Copy link
Copy Markdown
Contributor

Brings the PR-gate typecheck job from 31 errors to 0. Most of the noise was framework-shaped metaprogramming pyright can't follow without proper stubs (pyfly Body/Valid/Header/PathVar markers + pydantic populate_by_name aliases); the rest was real localised type issues fixed inline. Verified locally: pyright clean, ruff clean, 94/94 unit tests pass. See commit message for the per-area justification.

ancongui added 2 commits May 14, 2026 17:27
Brings the PR-gate's typecheck job from 31 errors to 0. Most of the
noise was framework-shaped metaprogramming pyright can't follow
without proper type stubs; the rest was real but localised.

* ``main.py`` -- replace the four ``_pyfly._private = …`` writes with
  ``setattr`` so pyright accepts the dynamic attribute mutation that
  pyfly's lifespan flow expects. ``# noqa: B010`` overrides the ruff
  rule that prefers direct assignment in this one place.

* ``core/services/rules/rule_engine.py`` -- guard the inner row
  iteration so a non-list ``fieldValueFound`` (the value-side of the
  scalar leaves) doesn't fail pyright's iterable check. Real runtime
  improvement: previously a malformed payload would have raised
  ``TypeError`` inside the rule serialiser; now it skips silently.

* ``core/observability/outbound_log.py`` -- mark the optional
  ``get_cost_calculator`` import as ``pyright: ignore`` and explain
  why (the symbol moves between agentic releases and is already
  wrapped in a broad try/except so missing pricing degrades to a
  zero-cost log line).

* ``pyproject.toml`` -- two ``pyright.executionEnvironments``
  overrides surface the framework-level limitations without
  per-line ``cast()`` clutter:
    - ``web/controllers``: pyfly's ``Body[T]`` / ``Valid[T]`` /
      ``Header[T]`` / ``PathVar[T]`` are runtime ``Generic[T]`` markers
      stripped at injection time; pyright sees them as opaque
      wrappers. Suppress ``reportArgumentType`` until pyfly switches
      to ``Annotated[T, …]`` or publishes proper stubs.
    - ``core/services/extraction``: pydantic v2's
      ``populate_by_name=True`` lets constructors accept either the
      Python field name (``fieldName=``) or the alias (``name=``).
      Pyright tracks the alias only, so it rejects the python-name
      callsites. Suppress ``reportCallIssue`` here.

Verified locally:
* pyright src/flydesk_idp -- 0 errors, 0 warnings, 0 informations
* ruff check . -- clean
* ruff format --check . -- clean
* pytest -q tests/unit -- 94 passed
In CI the agentic-main clone doesn't export observability.cost,
so the import line itself raises reportMissingImports. Moving the
suppression to the from … line (and keeping
reportAttributeAccessIssue on the symbol for local checkouts
where the module is reachable but pyright still can't bind the
symbol) makes the CI typecheck job land at 0 errors -- not just
advisory-green via continue-on-error.
@ancongui
ancongui merged commit 96ba8ed into main May 14, 2026
4 checks passed
@ancongui
ancongui deleted the chore/clean-pyright-advisory branch May 14, 2026 15:34
ancongui added a commit that referenced this pull request May 31, 2026
* chore(typing): silence the pyright advisory output

Brings the PR-gate's typecheck job from 31 errors to 0. Most of the
noise was framework-shaped metaprogramming pyright can't follow
without proper type stubs; the rest was real but localised.

* ``main.py`` -- replace the four ``_pyfly._private = …`` writes with
  ``setattr`` so pyright accepts the dynamic attribute mutation that
  pyfly's lifespan flow expects. ``# noqa: B010`` overrides the ruff
  rule that prefers direct assignment in this one place.

* ``core/services/rules/rule_engine.py`` -- guard the inner row
  iteration so a non-list ``fieldValueFound`` (the value-side of the
  scalar leaves) doesn't fail pyright's iterable check. Real runtime
  improvement: previously a malformed payload would have raised
  ``TypeError`` inside the rule serialiser; now it skips silently.

* ``core/observability/outbound_log.py`` -- mark the optional
  ``get_cost_calculator`` import as ``pyright: ignore`` and explain
  why (the symbol moves between agentic releases and is already
  wrapped in a broad try/except so missing pricing degrades to a
  zero-cost log line).

* ``pyproject.toml`` -- two ``pyright.executionEnvironments``
  overrides surface the framework-level limitations without
  per-line ``cast()`` clutter:
    - ``web/controllers``: pyfly's ``Body[T]`` / ``Valid[T]`` /
      ``Header[T]`` / ``PathVar[T]`` are runtime ``Generic[T]`` markers
      stripped at injection time; pyright sees them as opaque
      wrappers. Suppress ``reportArgumentType`` until pyfly switches
      to ``Annotated[T, …]`` or publishes proper stubs.
    - ``core/services/extraction``: pydantic v2's
      ``populate_by_name=True`` lets constructors accept either the
      Python field name (``fieldName=``) or the alias (``name=``).
      Pyright tracks the alias only, so it rejects the python-name
      callsites. Suppress ``reportCallIssue`` here.

Verified locally:
* pyright src/flydesk_idp -- 0 errors, 0 warnings, 0 informations
* ruff check . -- clean
* ruff format --check . -- clean
* pytest -q tests/unit -- 94 passed

* chore(typing): move pyright ignore to import line for CI parity

In CI the agentic-main clone doesn't export observability.cost,
so the import line itself raises reportMissingImports. Moving the
suppression to the from … line (and keeping
reportAttributeAccessIssue on the symbol for local checkouts
where the module is reachable but pyright still can't bind the
symbol) makes the CI typecheck job land at 0 errors -- not just
advisory-green via continue-on-error.

---------

Co-authored-by: ancongui <andres.contreras@soon.es>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant