-
Notifications
You must be signed in to change notification settings - Fork 197
Add more typing to debugpy and switch to 'standard' type checking mode #1637
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
base: main
Are you sure you want to change the base?
Changes from all commits
3d7808e
e528e2d
622e3c6
50e8d1d
063bb6a
5dd7fe9
3ee1940
891d5df
931d83c
7a1350a
8ce6670
4d609d2
fddf0de
c02affd
bfd9b88
046fe6f
0196522
fac2692
6e3bde7
8b8467a
2ce0c69
e5f1889
9c7c06b
4ce8028
6d50fc5
1478a48
04bd449
fbb7bd4
61402bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,12 @@ | |
| # for license information. | ||
|
|
||
| import functools | ||
| from typing import TYPE_CHECKING, Type, TypeVar, Union, cast | ||
|
|
||
| if TYPE_CHECKING: | ||
| # Dont import this during runtime. There's an order | ||
| # of imports issue that causes the debugger to hang. | ||
| from debugpy.adapter.sessions import Session | ||
| from debugpy.common import json, log, messaging, util | ||
|
|
||
|
|
||
|
|
@@ -31,7 +36,7 @@ class Component(util.Observable): | |
| to wait_for() a change caused by another component. | ||
| """ | ||
|
|
||
| def __init__(self, session, stream=None, channel=None): | ||
| def __init__(self, session: "Session", stream: "Union[messaging.JsonIOStream, None]"=None, channel: "Union[messaging.JsonMessageChannel, None]"=None): | ||
| assert (stream is None) ^ (channel is None) | ||
|
|
||
| try: | ||
|
|
@@ -44,18 +49,19 @@ def __init__(self, session, stream=None, channel=None): | |
|
|
||
| self.session = session | ||
|
|
||
| if channel is None: | ||
| if channel is None and stream is not None: | ||
| stream.name = str(self) | ||
| channel = messaging.JsonMessageChannel(stream, self) | ||
| channel.start() | ||
| else: | ||
| elif channel is not None: | ||
| channel.name = channel.stream.name = str(self) | ||
| channel.handlers = self | ||
| assert channel is not None | ||
| self.channel = channel | ||
| self.is_connected = True | ||
|
|
||
| # Do this last to avoid triggering useless notifications for assignments above. | ||
| self.observers += [lambda *_: self.session.notify_changed()] | ||
| self.observers = [*self.observers, lambda *_: self.session.notify_changed()] | ||
|
|
||
| def __str__(self): | ||
| return f"{type(self).__name__}[{self.session.id}]" | ||
|
|
@@ -108,8 +114,9 @@ def disconnect(self): | |
| self.is_connected = False | ||
| self.session.finalize("{0} has disconnected".format(self)) | ||
|
|
||
| T = TypeVar('T') | ||
|
|
||
| def missing(session, type): | ||
| def missing(session, type: Type[T]) -> T: | ||
| class Missing(object): | ||
| """A dummy component that raises ComponentNotAvailable whenever some | ||
| attribute is accessed on it. | ||
|
|
@@ -124,7 +131,7 @@ def report(): | |
| except Exception as exc: | ||
| log.reraise_exception("{0} in {1}", exc, session) | ||
|
|
||
| return Missing() | ||
| return cast(type, Missing()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📍 src/debugpy/adapter/components.py:134 Standard checking reports [verified] |
||
|
|
||
|
|
||
| class Capabilities(dict): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.