Skip to content

fix(vllm): stop the envs __getattr__ hiding typos from mypy - #13680

Open
ayaangazali wants to merge 1 commit into
ai-dynamo:mainfrom
ayaangazali:fix/vllm-envs-getattr-typing
Open

ayaangazali wants to merge 1 commit into
ai-dynamo:mainfrom
ayaangazali:fix/vllm-envs-getattr-typing

Conversation

@ayaangazali

@ayaangazali ayaangazali commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

dynamo/vllm/envs.py resolves its environment-backed values through a module-level __getattr__. mypy treats a module that defines __getattr__ as possibly having any attribute, so a typo checks clean:

envs.DYN_FORWADPASS_METRIC_PORT     # note the missing R

and it checks clean in every module that imports envs, not just inside this file.

What makes this the clearest of these cases is that the module already declares DYN_FORWARDPASS_METRIC_PORT: int under TYPE_CHECKING. The intent to keep the name statically visible is already expressed in the file; only the guard was missing. Putting __getattr__ behind if not TYPE_CHECKING makes the checker see exactly the declared name and nothing else.

This is the same correction @GuanLuo asked for on #13626, and the same one applied to the two dynamo/common packages in #13666. Kept to one file and one owner area on purpose rather than bundling the remaining packages together.

Validation

Checked with a control, because "mypy reports no error" can also mean the module was never really analysed. The declared name is used as that control: it resolves to int both before and after, so the probe is known to be reading real type information.

probe before after
reveal_type(envs.DYN_FORWARDPASS_METRIC_PORT) int int
envs.DYN_TYPO_DOES_NOT_EXIST no error Module has no attribute "DYN_TYPO_DOES_NOT_EXIST" [attr-defined]

Runtime behaviour is unchanged, exercised directly rather than argued:

  • envs.DYN_FORWARDPASS_METRIC_PORT resolves to the default 20380.
  • Setting the variable to 20999 is honoured on the next access, so the lookup is still lazy rather than captured at import.
  • Setting it to 99 still raises the range error (port 99 is outside of the registered port range), so _resolve_port validation is intact.
  • An unknown attribute still raises AttributeError: module 'dynamo.vllm.envs' has no attribute 'DYN_NOPE'.
  • __dir__() still returns ['DYN_FORWARDPASS_METRIC_PORT'] and is_set still works.

Test runs:

  • pytest components/src/dynamo/vllm/tests is 113 passed, 7 errors, identical on clean main with the change stashed. The 7 are test_state_agent.py collection errors unrelated to this file.
  • test_vllm_unit.py is the one test module that touches envs, and it cannot be collected here at all (ModuleNotFoundError: No module named 'vllm'), on this branch and on clean main alike. I did not want to claim coverage I do not have, so the runtime checks above were run directly against the module instead.
  • mypy clean on the file, pre-commit run --files passes with zero failing hooks.

Open in Devin Review

Summary by CodeRabbit

  • Bug Fixes
    • Improved runtime handling of environment-based settings.
    • Preserved clear errors when an unavailable setting is requested.
    • Enhanced compatibility with static type checking without changing the public interface.

`dynamo/vllm/envs.py` resolves its environment-backed values through a
module-level `__getattr__`. mypy treats a module that defines `__getattr__` as
possibly having any attribute, so a typo checks clean:

    envs.DYN_FORWADPASS_METRIC_PORT   # note the missing R

and it checks clean in every module that imports `envs`, not only here.

The module already declares `DYN_FORWARDPASS_METRIC_PORT: int` under
`TYPE_CHECKING`, so the intent to keep the name statically visible is already
expressed; only the guard was missing. Putting `__getattr__` behind
`if not TYPE_CHECKING` makes the checker see exactly the declared name and
nothing else.

No runtime change. The value still resolves lazily through
`environment_variables`, an unknown name still raises `AttributeError`, the
port range validation still fires, `is_set` and `__dir__` are untouched.

Same correction @GuanLuo asked for on ai-dynamo#13626, and the same one applied to the
two `dynamo/common` packages in ai-dynamo#13666.

Signed-off-by: ayaangazali <ayaangazali.work@gmail.com>
@ayaangazali
ayaangazali requested a review from a team as a code owner August 22, 2026 20:05
Copilot AI lite review requested due to automatic review settings August 22, 2026 20:05
@copy-pr-bot

copy-pr-bot Bot commented Aug 22, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ayaangazali
ayaangazali temporarily deployed to external_collaborator August 22, 2026 20:05 — with GitHub Actions Inactive
@ayaangazali
ayaangazali temporarily deployed to external_collaborator August 22, 2026 20:05 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added the fix label Aug 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi ayaangazali! Thank you for contributing to ai-dynamo/dynamo.

Just a reminder: The NVIDIA Test Github Validation CI runs an essential subset of the testing framework to quickly catch errors.Your PR reviewers may elect to test the changes comprehensively before approving your changes.

🚀

@github-actions github-actions Bot added external-contribution Pull request is from an external contributor backend::vllm Relates to the vllm backend labels Aug 22, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e04fc111-349e-4342-a1a7-da8db58f9855

📥 Commits

Reviewing files that changed from the base of the PR and between bb3100e and 3affd52.

📒 Files selected for processing (1)
  • components/src/dynamo/vllm/envs.py

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


Walkthrough

The change limits the module-level lazy __getattr__ definition to runtime execution. Runtime environment-variable lookup and missing-attribute handling remain unchanged.

Changes

VLLM environment lookup

Layer / File(s) Summary
Guard lazy environment lookup
components/src/dynamo/vllm/envs.py
Defines module-level __getattr__ only when TYPE_CHECKING is false. Preserves runtime lookup and AttributeError behavior.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 3affd

This localized change preserves runtime environment lookup behavior while making misspelled attributes fail static type checking; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the typing fix that prevents mypy from accepting misspelled vLLM environment attributes.
Description check ✅ Passed The description clearly explains the change and validation, but it omits the template headings and the required Related Issues confirmation.

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions Bot added the Stale label Sep 22, 2026

This branch was previously deployed

1 inactive deployment
external_collaborator — 3affd52f Deployed Aug 22, 2026 by ayaangazali via ok-to-test #11869
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend::vllm Relates to the vllm backend external-contribution Pull request is from an external contributor fix size/S Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants