Skip to content

Commit 4c8da78

Browse files
Import __future__ annotations (#2458)
* Import __future__ annotations This commit... 1. adds `from __future__ import annotations` to each relevant module in order to enable language level type annotation support. 2. as a result most quotation marks can be removed from type annotations. * Remove quotes from return types * Avoid conflict with PR #2456 --------- Co-authored-by: Предраг Николић <[email protected]>
1 parent 0ae1c7b commit 4c8da78

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+239
-157
lines changed

boot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
import os
23
import sublime
34
import sublime_plugin

plugin/code_actions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .core.promise import Promise
23
from .core.protocol import CodeAction
34
from .core.protocol import CodeActionKind

plugin/code_lens.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .core.constants import CODE_LENS_ENABLED_KEY
23
from .core.protocol import CodeLens
34
from .core.protocol import CodeLensExtended

plugin/color.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .core.edit import apply_text_edits
23
from .core.protocol import ColorInformation
34
from .core.protocol import ColorPresentation

plugin/completion.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .core.constants import COMPLETION_KINDS
23
from .core.edit import apply_text_edits
34
from .core.logging import debug
@@ -28,17 +29,17 @@
2829
from .core.views import update_lsp_popup
2930
from typing import Any, Callable, Dict, Generator, List, Optional, Tuple, Union
3031
from typing import cast
31-
from typing_extensions import TypeGuard
32+
from typing_extensions import TypeAlias, TypeGuard
3233
import functools
3334
import html
3435
import sublime
3536
import weakref
3637
import webbrowser
3738

38-
SessionName = str
39-
CompletionResponse = Union[List[CompletionItem], CompletionList, None]
40-
ResolvedCompletions = Tuple[Union[CompletionResponse, Error], 'weakref.ref[Session]']
41-
CompletionsStore = Tuple[List[CompletionItem], CompletionItemDefaults]
39+
SessionName: TypeAlias = str
40+
CompletionResponse: TypeAlias = Union[List[CompletionItem], CompletionList, None]
41+
ResolvedCompletions: TypeAlias = Tuple[Union[CompletionResponse, Error], 'weakref.ref[Session]']
42+
CompletionsStore: TypeAlias = Tuple[List[CompletionItem], CompletionItemDefaults]
4243

4344

4445
def format_completion(
@@ -199,7 +200,7 @@ def _create_completion_request_async(self, session: Session) -> Promise[Resolved
199200
return promise.then(lambda response: self._on_completion_response_async(response, request_id, weak_session))
200201

201202
def _on_completion_response_async(
202-
self, response: CompletionResponse, request_id: int, weak_session: 'weakref.ref[Session]'
203+
self, response: CompletionResponse, request_id: int, weak_session: weakref.ref[Session]
203204
) -> ResolvedCompletions:
204205
self._pending_completion_requests.pop(request_id, None)
205206
return (response, weak_session)

plugin/configuration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .core.registry import windows
23
from .core.settings import client_configs
34
from .core.windows import WindowManager

plugin/core/active_request.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .sessions import SessionViewProtocol
23
from .progress import ProgressReporter
34
from .progress import ViewProgressReporter

plugin/core/collections.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Module with additional collections.
33
"""
4+
from __future__ import annotations
45
from copy import deepcopy
56
from typing import Any, Dict, Generator, Optional
67
import sublime

plugin/core/configurations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .logging import debug
23
from .logging import exception_log
34
from .logging import printf

plugin/core/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .protocol import CodeActionKind
23
from .protocol import CompletionItemKind
34
from .protocol import DiagnosticSeverity

plugin/core/css.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from typing import Optional
23
import sublime
34

plugin/core/diagnostics_storage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .protocol import Diagnostic, DiagnosticSeverity, DocumentUri
23
from .url import parse_uri
34
from .views import diagnostic_severity

plugin/core/edit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .logging import debug
23
from .protocol import Position
34
from .protocol import TextEdit

plugin/core/file_watcher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .protocol import FileChangeType
23
from .protocol import WatchKind
34
from abc import ABCMeta
@@ -58,7 +59,7 @@ def create(
5859
events: List[FileWatcherEventType],
5960
ignores: List[str],
6061
handler: FileWatcherProtocol
61-
) -> 'FileWatcher':
62+
) -> FileWatcher:
6263
"""
6364
Creates a new instance of the file watcher.
6465

plugin/core/input_handlers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .constants import ST_VERSION
23
from abc import ABCMeta
34
from abc import abstractmethod

plugin/core/logging.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from typing import Any
23
import traceback
34
import inspect

plugin/core/message_request_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .protocol import MessageType
23
from .protocol import Response
34
from .protocol import ShowMessageRequestParams

plugin/core/open.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .constants import ST_VERSION
23
from .logging import exception_log
34
from .promise import Promise

plugin/core/panels.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .types import PANEL_FILE_REGEX
23
from .types import PANEL_LINE_REGEX
34
from typing import Iterable, Optional

plugin/core/paths.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from .protocol import DocumentUri
23
from .sessions import Session
34
from .views import parse_uri

plugin/core/progress.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from typing import Optional, Union
23
import sublime
34

plugin/core/promise.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from typing import Callable, Generic, List, Optional, Protocol, Tuple, TypeVar, Union
23
import functools
34
import threading
@@ -65,7 +66,7 @@ def process_value(value):
6566
"""
6667

6768
@staticmethod
68-
def resolve(resolve_value: S) -> 'Promise[S]':
69+
def resolve(resolve_value: S) -> Promise[S]:
6970
"""Immediately resolves a Promise.
7071
7172
Convenience function for creating a Promise that gets immediately
@@ -99,7 +100,7 @@ def __call__(self, resolver: ResolveFunc[TExecutor]) -> None:
99100

100101
# Could also support passing plain S.
101102
@staticmethod
102-
def all(promises: List['Promise[S]']) -> 'Promise[List[S]]':
103+
def all(promises: List[Promise[S]]) -> Promise[List[S]]:
103104
"""
104105
Takes a list of promises and returns a Promise that gets resolved when all promises
105106
gets resolved.
@@ -147,7 +148,7 @@ def __repr__(self) -> str:
147148
return 'Promise({})'.format(self.value)
148149
return 'Promise(<pending>)'
149150

150-
def then(self, onfullfilled: FullfillFunc[T, TResult]) -> 'Promise[TResult]':
151+
def then(self, onfullfilled: FullfillFunc[T, TResult]) -> Promise[TResult]:
151152
"""Create a new promise and chain it with this promise.
152153
153154
When this promise gets resolved, the callback will be called with the

0 commit comments

Comments
 (0)