Skip to content

Commit e98a865

Browse files
committed
style: remove some unused code and comments
1 parent b478ae3 commit e98a865

28 files changed

+62
-299
lines changed

packages/core/src/robotcode/core/async_tools.py

Lines changed: 0 additions & 233 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import concurrent.futures
66
import contextvars
77
import functools
8-
import inspect
98
import threading
109
import time
1110
import warnings
@@ -15,14 +14,9 @@
1514
from types import TracebackType
1615
from typing import (
1716
Any,
18-
AsyncIterator,
1917
Callable,
2018
Coroutine,
2119
Deque,
22-
Generic,
23-
Iterator,
24-
List,
25-
MutableSet,
2620
Optional,
2721
Set,
2822
Type,
@@ -31,235 +25,8 @@
3125
cast,
3226
)
3327

34-
from .concurrent import is_threaded_callable
35-
from .utils.inspect import ensure_coroutine
36-
3728
_T = TypeVar("_T")
3829

39-
# TODO try to use new ParamSpec feature in Python 3.10
40-
41-
_TResult = TypeVar("_TResult")
42-
_TCallable = TypeVar("_TCallable", bound=Callable[..., Any])
43-
44-
45-
class AsyncEventResultIteratorBase(Generic[_TCallable, _TResult]):
46-
def __init__(self) -> None:
47-
self._lock = threading.RLock()
48-
49-
self._listeners: MutableSet[weakref.ref[Any]] = set()
50-
self._loop = asyncio.get_event_loop()
51-
52-
def add(self, callback: _TCallable) -> None:
53-
def remove_listener(ref: Any) -> None:
54-
with self._lock:
55-
self._listeners.remove(ref)
56-
57-
with self._lock:
58-
if inspect.ismethod(callback):
59-
self._listeners.add(weakref.WeakMethod(callback, remove_listener))
60-
else:
61-
self._listeners.add(weakref.ref(callback, remove_listener))
62-
63-
def remove(self, callback: _TCallable) -> None:
64-
with self._lock:
65-
try:
66-
if inspect.ismethod(callback):
67-
self._listeners.remove(weakref.WeakMethod(callback))
68-
else:
69-
self._listeners.remove(weakref.ref(callback))
70-
except KeyError:
71-
pass
72-
73-
def __contains__(self, obj: Any) -> bool:
74-
if inspect.ismethod(obj):
75-
return weakref.WeakMethod(obj) in self._listeners
76-
77-
return weakref.ref(obj) in self._listeners
78-
79-
def __len__(self) -> int:
80-
return len(self._listeners)
81-
82-
def __iter__(self) -> Iterator[_TCallable]:
83-
for r in self._listeners:
84-
c = r()
85-
if c is not None:
86-
yield c
87-
88-
async def __aiter__(self) -> AsyncIterator[_TCallable]:
89-
for r in self.__iter__():
90-
yield r
91-
92-
async def _notify(
93-
self,
94-
*args: Any,
95-
callback_filter: Optional[Callable[[_TCallable], bool]] = None,
96-
**kwargs: Any,
97-
) -> AsyncIterator[_TResult]:
98-
for method in filter(
99-
lambda x: callback_filter(x) if callback_filter is not None else True,
100-
set(self),
101-
):
102-
result = method(*args, **kwargs)
103-
if inspect.isawaitable(result):
104-
result = await result
105-
106-
yield result
107-
108-
109-
class AsyncEventIterator(AsyncEventResultIteratorBase[_TCallable, _TResult]):
110-
def __call__(self, *args: Any, **kwargs: Any) -> AsyncIterator[_TResult]:
111-
return self._notify(*args, **kwargs)
112-
113-
114-
class AsyncEvent(AsyncEventResultIteratorBase[_TCallable, _TResult]):
115-
async def __call__(self, *args: Any, **kwargs: Any) -> List[_TResult]:
116-
return [a async for a in self._notify(*args, **kwargs)]
117-
118-
119-
_TEvent = TypeVar("_TEvent")
120-
121-
122-
class AsyncEventDescriptorBase(Generic[_TCallable, _TResult, _TEvent]):
123-
def __init__(
124-
self,
125-
_func: _TCallable,
126-
factory: Callable[..., _TEvent],
127-
*factory_args: Any,
128-
**factory_kwargs: Any,
129-
) -> None:
130-
self._func = _func
131-
self.__factory = factory
132-
self.__factory_args = factory_args
133-
self.__factory_kwargs = factory_kwargs
134-
self._owner: Optional[Any] = None
135-
self._owner_name: Optional[str] = None
136-
137-
def __set_name__(self, owner: Any, name: str) -> None:
138-
self._owner = owner
139-
self._owner_name = name
140-
141-
def __get__(self, obj: Any, objtype: Type[Any]) -> _TEvent:
142-
if obj is None:
143-
return self # type: ignore
144-
145-
name = f"__async_event_{self._func.__name__}__"
146-
if not hasattr(obj, name):
147-
setattr(
148-
obj,
149-
name,
150-
self.__factory(*self.__factory_args, **self.__factory_kwargs),
151-
)
152-
153-
return cast("_TEvent", getattr(obj, name))
154-
155-
156-
class async_event_iterator( # noqa: N801
157-
AsyncEventDescriptorBase[_TCallable, Any, AsyncEventIterator[_TCallable, Any]]
158-
):
159-
def __init__(self, _func: _TCallable) -> None:
160-
super().__init__(_func, AsyncEventIterator[_TCallable, Any])
161-
162-
163-
class async_event(AsyncEventDescriptorBase[_TCallable, Any, AsyncEvent[_TCallable, Any]]): # noqa: N801
164-
def __init__(self, _func: _TCallable) -> None:
165-
super().__init__(_func, AsyncEvent[_TCallable, Any])
166-
167-
168-
class AsyncTaskingEventResultIteratorBase(AsyncEventResultIteratorBase[_TCallable, _TResult]):
169-
def __init__(self, *, task_name_prefix: Optional[str] = None) -> None:
170-
super().__init__()
171-
self._task_name_prefix = task_name_prefix or type(self).__qualname__
172-
173-
async def _notify( # type: ignore
174-
self,
175-
*args: Any,
176-
result_callback: Optional[Callable[[Optional[_TResult], Optional[BaseException]], Any]] = None,
177-
return_exceptions: Optional[bool] = True,
178-
callback_filter: Optional[Callable[[_TCallable], bool]] = None,
179-
threaded: Optional[bool] = True,
180-
**kwargs: Any,
181-
) -> AsyncIterator[Union[_TResult, BaseException]]:
182-
def _done(f: asyncio.Future[_TResult]) -> None:
183-
if result_callback is not None:
184-
try:
185-
result_callback(f.result(), f.exception())
186-
except (SystemExit, KeyboardInterrupt):
187-
raise
188-
except BaseException as e:
189-
result_callback(None, e)
190-
191-
awaitables: List[asyncio.Future[_TResult]] = []
192-
for method in filter(
193-
lambda x: callback_filter(x) if callback_filter is not None else True,
194-
set(self),
195-
):
196-
if method is not None:
197-
if threaded and is_threaded_callable(method):
198-
future = run_coroutine_in_thread(ensure_coroutine(method), *args, **kwargs)
199-
else:
200-
future = create_sub_task(ensure_coroutine(method)(*args, **kwargs))
201-
awaitables.append(future)
202-
203-
if result_callback is not None:
204-
future.add_done_callback(_done)
205-
206-
for a in asyncio.as_completed(awaitables):
207-
try:
208-
yield await a
209-
210-
except (SystemExit, KeyboardInterrupt):
211-
raise
212-
except BaseException as e:
213-
if return_exceptions:
214-
yield e
215-
else:
216-
raise
217-
218-
219-
class AsyncTaskingEventIterator(AsyncTaskingEventResultIteratorBase[_TCallable, _TResult]):
220-
def __call__(self, *args: Any, **kwargs: Any) -> AsyncIterator[Union[_TResult, BaseException]]:
221-
return self._notify(*args, **kwargs)
222-
223-
224-
def _get_name_prefix(
225-
descriptor: AsyncEventDescriptorBase[Any, Any, Any],
226-
) -> str:
227-
if descriptor._owner is None:
228-
return type(descriptor).__qualname__
229-
230-
return f"{descriptor._owner.__qualname__}.{descriptor._owner_name}"
231-
232-
233-
class AsyncTaskingEvent(AsyncTaskingEventResultIteratorBase[_TCallable, _TResult]):
234-
async def __call__(self, *args: Any, **kwargs: Any) -> List[Union[_TResult, BaseException]]:
235-
return [a async for a in self._notify(*args, **kwargs)]
236-
237-
238-
class async_tasking_event_iterator( # noqa: N801
239-
AsyncEventDescriptorBase[_TCallable, Any, AsyncTaskingEventIterator[_TCallable, Any]]
240-
):
241-
def __init__(self, _func: _TCallable) -> None:
242-
super().__init__(
243-
_func,
244-
AsyncTaskingEventIterator[_TCallable, Any],
245-
task_name_prefix=lambda: _get_name_prefix(self),
246-
)
247-
248-
249-
class async_tasking_event(AsyncEventDescriptorBase[_TCallable, Any, AsyncTaskingEvent[_TCallable, Any]]): # noqa: N801
250-
def __init__(self, _func: _TCallable) -> None:
251-
super().__init__(
252-
_func,
253-
AsyncTaskingEvent[_TCallable, Any],
254-
task_name_prefix=lambda: _get_name_prefix(self),
255-
)
256-
257-
258-
async def check_canceled() -> bool:
259-
await asyncio.sleep(0)
260-
261-
return True
262-
26330

26431
def check_canceled_sync() -> bool:
26532
info = get_current_future_info()

packages/debugger/src/robotcode/debugger/debugger.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ def __init__(self) -> None:
312312
self.stop_on_entry = False
313313
self._debug = True
314314
self.terminated = False
315-
self.terminated_requested = False
316315
self.attached = False
317316
self.path_mappings: List[PathMapping] = []
318317
self.server_loop: Optional[asyncio.AbstractEventLoop] = None
@@ -383,9 +382,6 @@ def robot_output_file(self) -> Optional[str]:
383382
def robot_output_file(self, value: Optional[str]) -> None:
384383
self._robot_output_file = value
385384

386-
def terminate_requested(self) -> None:
387-
self.terminated_requested = True
388-
389385
def terminate(self) -> None:
390386
self.terminated = True
391387

@@ -504,7 +500,7 @@ def step_out(self, thread_id: int, granularity: Optional[SteppingGranularity] =
504500
self.condition.notify_all()
505501

506502
@event
507-
def send_event(sender: Any, event: Event) -> None: # NOSONAR
503+
def send_event(sender: Any, event: Event) -> None:
508504
...
509505

510506
def set_breakpoints(

packages/language_server/src/robotcode/language_server/common/parts/code_action.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ def collect(
4141
sender,
4242
document: TextDocument,
4343
range: Range,
44-
context: CodeActionContext, # NOSONAR
44+
context: CodeActionContext,
4545
) -> Optional[List[Union[Command, CodeAction]]]:
4646
...
4747

4848
@event
49-
def resolve(sender, code_action: CodeAction) -> Optional[CodeAction]: # NOSONAR
49+
def resolve(sender, code_action: CodeAction) -> Optional[CodeAction]:
5050
...
5151

5252
def extend_capabilities(self, capabilities: ServerCapabilities) -> None:

packages/language_server/src/robotcode/language_server/common/parts/code_lens.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def __init__(self, parent: "LanguageServerProtocol") -> None:
3030
self._refresh_timeout = 5
3131

3232
@event
33-
def collect(sender, document: TextDocument) -> Optional[List[CodeLens]]: # NOSONAR
33+
def collect(sender, document: TextDocument) -> Optional[List[CodeLens]]:
3434
...
3535

3636
@event
37-
def resolve(sender, code_lens: CodeLens) -> Optional[CodeLens]: # NOSONAR
37+
def resolve(sender, code_lens: CodeLens) -> Optional[CodeLens]:
3838
...
3939

4040
def extend_capabilities(self, capabilities: ServerCapabilities) -> None:

packages/language_server/src/robotcode/language_server/common/parts/completion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ def collect(
4747
sender,
4848
document: TextDocument,
4949
position: Position,
50-
context: Optional[CompletionContext], # NOSONAR
50+
context: Optional[CompletionContext],
5151
) -> Union[List[CompletionItem], CompletionList, None]:
5252
...
5353

5454
@event
55-
def resolve(sender, completion_item: CompletionItem) -> Optional[CompletionItem]: # NOSONAR
55+
def resolve(sender, completion_item: CompletionItem) -> Optional[CompletionItem]:
5656
...
5757

5858
def extend_capabilities(self, capabilities: ServerCapabilities) -> None:

packages/language_server/src/robotcode/language_server/common/parts/declaration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, parent: "LanguageServerProtocol") -> None:
3434
def collect(
3535
sender,
3636
document: TextDocument,
37-
position: Position, # NOSONAR
37+
position: Position,
3838
) -> Union[Location, List[Location], List[LocationLink], None]:
3939
...
4040

packages/language_server/src/robotcode/language_server/common/parts/definition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, parent: "LanguageServerProtocol") -> None:
3434
def collect(
3535
sender,
3636
document: TextDocument,
37-
position: Position, # NOSONAR
37+
position: Position,
3838
) -> Union[Location, List[Location], List[LocationLink], None]:
3939
...
4040

packages/language_server/src/robotcode/language_server/common/parts/diagnostics.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,25 @@ def extend_capabilities(self, capabilities: ServerCapabilities) -> None:
132132
self.client_supports_pull = True
133133

134134
@event
135-
def collect(sender, document: TextDocument) -> Optional[DiagnosticsResult]: # NOSONAR
135+
def collect(sender, document: TextDocument) -> Optional[DiagnosticsResult]:
136136
...
137137

138138
@event
139139
def load_workspace_documents(
140140
sender,
141-
) -> Optional[List[WorkspaceDocumentsResult]]: # NOSONAR
141+
) -> Optional[List[WorkspaceDocumentsResult]]:
142142
...
143143

144144
@event
145-
def on_workspace_loaded(sender) -> None: # NOSONAR
145+
def on_workspace_loaded(sender) -> None:
146146
...
147147

148148
@event
149-
def on_get_analysis_progress_mode(sender, uri: Uri) -> Optional[AnalysisProgressMode]: # NOSONAR
149+
def on_get_analysis_progress_mode(sender, uri: Uri) -> Optional[AnalysisProgressMode]:
150150
...
151151

152152
@event
153-
def on_get_diagnostics_mode(sender, uri: Uri) -> Optional[DiagnosticsMode]: # NOSONAR
153+
def on_get_diagnostics_mode(sender, uri: Uri) -> Optional[DiagnosticsMode]:
154154
...
155155

156156
def ensure_workspace_loaded(self) -> None:

packages/language_server/src/robotcode/language_server/common/parts/document_highlight.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def extend_capabilities(self, capabilities: ServerCapabilities) -> None:
3434
capabilities.document_highlight_provider = DocumentHighlightOptions(work_done_progress=True)
3535

3636
@event
37-
def collect(sender, document: TextDocument, position: Position) -> Optional[List[DocumentHighlight]]: # NOSONAR
37+
def collect(sender, document: TextDocument, position: Position) -> Optional[List[DocumentHighlight]]:
3838
...
3939

4040
@rpc_method(name="textDocument/documentHighlight", param_type=DocumentHighlightParams, threaded=True)

packages/language_server/src/robotcode/language_server/common/parts/document_symbols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(self, parent: "LanguageServerProtocol") -> None:
6666
@event
6767
def collect(
6868
sender,
69-
document: TextDocument, # NOSONAR
69+
document: TextDocument,
7070
) -> Optional[Union[List[DocumentSymbol], List[SymbolInformation], None]]:
7171
...
7272

0 commit comments

Comments
 (0)