-
Notifications
You must be signed in to change notification settings - Fork 139
Added initial typehints #494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
danielmorell
wants to merge
23
commits into
master
Choose a base branch
from
added/typehints
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3603881
Removed support for Python 3.6/3.7 missing ContextVar
danielmorell 2414d2a
Initial work on adding typing.
danielmorell 4813578
Merge branch 'master' into added/typehints
danielmorell 57d5945
Added type stubs and typed imports where possible ignored the rest
danielmorell eb58125
Merge branch 'master' into added/typehints
danielmorell 93194dc
Merge branch 'master' into added/typehints
danielmorell 9ef5009
Added initial round of typehints
danielmorell 158f79e
Fixed missing route passed to app init.
danielmorell 2312565
Fixed check_level function to allow custom levels.
danielmorell a8102b7
Removed commented code.
danielmorell 83434fc
Address review comments.
danielmorell a02b8c0
Fixed deprecated Starlette routing in tests.
danielmorell 1a3c08d
More code review fixes.
danielmorell e15edf1
Removed unnecessary missing contextvar test.
danielmorell 6318c76
Addressed code review comments.
danielmorell 3fe9121
Dropped support for Python 3.9
danielmorell f347608
Updated 3.9 Unions and Optional to modern syntax
danielmorell 50e8438
Moved type only imports to behind typing.TYPE_CHECKING.
danielmorell fba47bd
Require mypy < 2.0 until it is more stable.
danielmorell 944c701
Fixed FastAPI tests skipped because of incorrect version.
danielmorell 2557198
Fixed tests and addressed review comments.
danielmorell 98944e5
Fixed httpx JSON encoding in FastAPI tests.
danielmorell ed68dc9
Fixed adjustment to JSON body in FastAPI tests.
danielmorell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Test file
rollbar/test/fastapi_tests/test_routing.py:6directly importsfrom packaging.version import Version(new in this PR for the version comparison fix), butpackagingis not declared in thetestdependency group inpyproject.toml. This currently works only transitively because pytest declarespackaging>=22as a runtime requirement; declaring direct imports as direct deps is the same hygiene the PR already applied fortyping_extensions(added to runtime deps because the PR newly imports it). One-line fix: add"packaging",to thetestgroup around line 48.Extended reasoning...
What the bug is
This PR's
rollbar/test/fastapi_tests/test_routing.pynewly importsfrom packaging.version import Versionat line 6 — the import replaces an earlier lexicographicfastapi.__version__ >= '0.41.0'comparison with a properVersion(...)comparison (line 13), and is also used insidetest_should_send_payload_with_request_bodyto gate onVersion(httpx_version) >= Version('0.28.0'). Thetestdependency group inpyproject.toml(lines 47–54), however, lists only:No
packagingentry.Why it works today (and the refutation)
A refuting verifier correctly pointed out that pytest declares
packaging>=22as a hard runtime dependency, so any environment that installs thetestgroup transitively pullspackaging. CI therefore never sees anImportError. That argument is accurate, and is exactly why this is filed as a nit rather than normal severity — there is no current breakage and the practical risk is near-zero because pytest has required packaging for many releases.Why it's still worth flagging
The same PR explicitly applied the opposite convention one section above: it added
typing_extensions; python_version < "3.11"to the runtimedependencieslist (pyproject.toml:44) precisely because the PR newly introducedfrom typing_extensions import Unpackinrollbar/__init__.py. The 'if you directly import it, declare it' rule is therefore the rule this PR itself sets. Leavingpackagingas a transitive-only dep contradicts that rule by one line in the same file.Relying on transitive dependencies for direct imports is a well-known anti-pattern (PEP 508 / packaging best practices). The failure mode is small but real: if pytest ever drops its packaging dep (theoretical, but not impossible across major-version bumps), or if a downstream user installs the test target with a minimal resolver, the import fails at collection time because the import is at module scope and pytest evaluates it before any
skipUnlessguard runs.How to fix
Single-line change in
pyproject.tomlaround line 48:Step-by-step proof
rollbar/test/fastapi_tests/test_routing.py:6—from packaging.version import Version. Unconditional, module-scope import (pytest collection alone triggers it).rollbar/test/fastapi_tests/test_routing.py:13—ALLOWED_FASTAPI_VERSION = Version(fastapi.__version__) >= Version('0.41.0'). Confirms the import is actually used.pyproject.toml:47-54—testgroup hasblinker, httpx, pytest, python-multipart, webob. Nopackaging.pyproject.toml:42-45— runtimedependenciesnow includestyping_extensions; python_version < "3.11". Confirms this PR's own convention: 'direct import → direct declaration'.packagingis currently available in every test environment only becausepytest(in thetestgroup) declaresRequires-Dist: packaging>=22in its METADATA. That is a transitive guarantee, not a direct one.