Add more typing to debugpy and switch to 'standard' type checking mode - #1637
Open
Rich Chiodo (rchiodo) wants to merge 41 commits into
Open
Add more typing to debugpy and switch to 'standard' type checking mode#1637Rich Chiodo (rchiodo) wants to merge 41 commits into
Rich Chiodo (rchiodo) wants to merge 41 commits into
Conversation
Erik De Bonte (debonte)
previously approved these changes
Jul 24, 2024
…odo/type_standard # Conflicts: # CONTRIBUTING.md # src/debugpy/adapter/clients.py # src/debugpy/adapter/launchers.py # src/debugpy/adapter/servers.py # src/debugpy/common/sockets.py # src/debugpy/server/api.py # src/debugpy/server/cli.py # tests/requirements.txt
Contributor
|
🔒 Automated review in progress — Heejae Chang (@heejaechang) is auto-reviewing this PR. |
Heejae Chang (heejaechang)
approved these changes
Jul 21, 2026
Heejae Chang (heejaechang)
left a comment
Contributor
There was a problem hiding this comment.
Approved via Review Center.
pytest-retry re-runs flaky tests' setup/call phases directly without firing pytest_runtest_makereport, so pytest 9's tmp_path finalizer never repopulates its tmppath_result_key stash entry after the first attempt's teardown deletes it, raising KeyError at teardown (seen on py314 when test_attach_pid_client was retried). Re-seed the stash key in a pytest_runtest_setup hook, which pytest-retry runs on each retry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
🔒 Automated review in progress — Stella Huang (@StellaHuang95) is auto-reviewing this PR. |
Stella Huang (StellaHuang95)
approved these changes
Aug 6, 2026
Stella Huang (StellaHuang95)
left a comment
Contributor
There was a problem hiding this comment.
Approved via Review Center.
Address review feedback: cover the owned-vs-unlocked invariant that assert_locked now enforces (_is_owned() check). Verifies attribute access succeeds when the current thread owns the lock and fails fast (AssertionError) on read/write when unlocked. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Stella Huang (StellaHuang95)
approved these changes
Aug 6, 2026
Stella Huang (StellaHuang95)
left a comment
Contributor
There was a problem hiding this comment.
Approved via Review Center.
# Conflicts: # src/debugpy/common/log.py
Stella Huang (StellaHuang95)
approved these changes
Aug 7, 2026
Stella Huang (StellaHuang95)
left a comment
Contributor
There was a problem hiding this comment.
Approved via Review Center.
- messaging.py: replace setattr-based _parse/_handle override on OutgoingRequest with explicit class-level typed optional attributes so the override stays statically visible to Pyright. - test_messaging.py: pin the respond(None) contract (Response.body is an empty MessageDict, never None), matching incoming empty responses. - test_json.py: add focused regression coverage pinning _converter to int/float and rejecting Decimal/complex/Fraction. - CONTRIBUTING.md: document the standard Pyright mode and the repository-wide prohibition on '# type: ignore' (use targeted '# pyright: ignore[...]'). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Stella Huang (StellaHuang95)
approved these changes
Aug 7, 2026
Stella Huang (StellaHuang95)
left a comment
Contributor
There was a problem hiding this comment.
Approved via Review Center.
Restores tests/debugpy/server/test_api.py (referenced by the PR description) with focused coverage for the empty-read -> EOFError path in debugpy.server.api.listen(): an empty read (b'') from the adapter endpoints socket must surface an EOFError rather than falling through to json.loads. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mark the class-local decorator helper static so Pyright no longer treats its wrapped callable as an instance-method self parameter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Stella Huang (StellaHuang95)
approved these changes
Aug 8, 2026
Stella Huang (StellaHuang95)
left a comment
Contributor
There was a problem hiding this comment.
Approved via Review Center.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds type annotations across
debugpyand switches Pyright tostandardtype-checking mode (typeCheckingMode = "standard"), with# type: ignorecomments disabled repository-wide (enableTypeIgnoreComments = false). It was originally used to exercise Pylance, but the stricter typing is a worthwhile improvement on its own.The vast majority of the diff is pure type annotations. However, a handful of non-annotation changes were needed (or surfaced by the stricter checking) and are called out below so reviewers do not have to infer them from the diff.
Non-annotation (behavioral) changes
adapter/clients.py–launch/attachhandling now preservesrequest_options; out-of-orderconfigurationDonerequests fail explicitly; and anevaluaterequest that cannot be propagated to the debug server now receives a failure response instead of hanging.adapter/launchers.py– for a debug launch,spawn_debuggeenow assertsservers.listener is not Nonebefore reading the address/token, restoring fail-fast behavior (and narrowing the Optional) instead of silently skipping connection info.common/messaging.pyMessage.__call__no longer usesassertfor control flow: it explicitly raises when the payload is anException, so behavior is identical underpython -O.Request.respond(None)now models a successful empty response as an emptyMessageDict(instead ofNone), matching how incoming empty responses are already parsed, soResponse.bodyis always aMessageDictor anException.OutgoingRequestdisables the inherited_parse/_handlevia explicit class-level attributes.common/singleton.py–ThreadSafeSingleton.assert_lockedis no longer a@staticmethodand uses a side-effect-freelock._is_owned()check instead ofacquire(blocking=False)/release(), avoiding an RLock recursion-count leak (and an unbalancedrelease()underpython -O).common/json.py–_converternarrows accepted numeric types fromnumbers.Numbertoint/floatonly (DAP number payloads are int/float;Decimal/complex/Fractionnever appear).common/util.py–Observable.observerskeeps an immutable()class default (typedSequence) and the+=call sites were switched to reassignment, avoiding mutation of a shared class attribute.server/api.py– an empty adapter-endpoints read now raises the intendedEOFErrorinstead of falling through tojson.loadsand surfacingJSONDecodeError.Focused regression tests were added for the behavioral changes (see
tests/debugpy/common/test_messaging.py,tests/debugpy/common/test_singleton.py,tests/debugpy/common/test_json.py, andtests/debugpy/server/test_api.py).Suppression policy
Because
enableTypeIgnoreComments = false,# type: ignorehas no effect and must not be used. Where a diagnostic must be suppressed (correct code the checker cannot verify, e.g. access to a private-but-stable runtime API), a narrow# pyright: ignore[reportSpecificRule]is used instead. This convention is now documented in CONTRIBUTING.md.