Skip to content
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

Import from typing, typing_extensions and enum modules on Python 3.8 #2446

Merged
merged 18 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from .plugin.core.transports import kill_all_subprocesses
from .plugin.core.tree_view import LspCollapseTreeItemCommand
from .plugin.core.tree_view import LspExpandTreeItemCommand
from .plugin.core.typing import Any, Optional, List, Type, Dict
from .plugin.core.views import LspRunTextCommandHelperCommand
from .plugin.document_link import LspOpenLinkCommand
from .plugin.documents import DocumentSyncListener
Expand Down Expand Up @@ -86,6 +85,7 @@
from .plugin.tooling import LspOnDoubleClickCommand
from .plugin.tooling import LspParseVscodePackageJson
from .plugin.tooling import LspTroubleshootServerCommand
from typing import Any, Dict, List, Optional, Type


def _get_final_subclasses(derived: List[Type], results: List[Type]) -> None:
Expand Down
1 change: 1 addition & 0 deletions dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
">=4096": [
"bracex",
"mdpopups",
"typing_extensions",
"wcmatch"
]
}
Expand Down
4 changes: 3 additions & 1 deletion plugin/code_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from .core.sessions import AbstractViewListener
from .core.sessions import SessionBufferProtocol
from .core.settings import userprefs
from .core.typing import Any, List, Dict, Callable, Optional, Tuple, TypeGuard, Union, cast
from .core.views import entire_content_region
from .core.views import first_selection_region
from .core.views import format_code_actions_for_quick_panel
Expand All @@ -21,6 +20,9 @@
from abc import ABCMeta
from abc import abstractmethod
from functools import partial
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
from typing import cast
from typing_extensions import TypeGuard
import sublime

ConfigName = str
Expand Down
3 changes: 2 additions & 1 deletion plugin/code_lens.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
from .core.protocol import CodeLens
from .core.protocol import CodeLensExtended
from .core.protocol import Error
from .core.typing import List, Tuple, Dict, Iterable, Optional, Generator, Union, cast
from .core.registry import LspTextCommand
from .core.registry import LspWindowCommand
from .core.registry import windows
from .core.views import make_command_link
from .core.views import range_to_region
from html import escape as html_escape
from functools import partial
from typing import Dict, Generator, Iterable, List, Optional, Tuple, Union
from typing import cast
import itertools
import sublime

Expand Down
2 changes: 1 addition & 1 deletion plugin/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from .core.protocol import ColorPresentationParams
from .core.protocol import Request
from .core.registry import LspTextCommand
from .core.typing import List
from .core.views import range_to_region
from .core.views import text_document_identifier
from typing import List
import sublime


Expand Down
4 changes: 3 additions & 1 deletion plugin/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
from .core.registry import LspTextCommand
from .core.sessions import Session
from .core.settings import userprefs
from .core.typing import Callable, List, Dict, Optional, Generator, Tuple, Union, cast, Any, TypeGuard
from .core.views import FORMAT_STRING, FORMAT_MARKUP_CONTENT
from .core.views import MarkdownLangMap
from .core.views import minihtml
from .core.views import range_to_region
from .core.views import show_lsp_popup
from .core.views import text_document_position_params
from .core.views import update_lsp_popup
from typing import Any, Callable, Dict, Generator, List, Optional, Tuple, Union
from typing import cast
from typing_extensions import TypeGuard
import functools
import html
import sublime
Expand Down
2 changes: 1 addition & 1 deletion plugin/core/active_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .progress import ViewProgressReporter
from .progress import WindowProgressReporter
from .protocol import Request
from .typing import Any, Optional, Dict
from typing import Any, Dict, Optional
from weakref import ref
import sublime

Expand Down
2 changes: 1 addition & 1 deletion plugin/core/collections.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
Module with additional collections.
"""
from .typing import Optional, Dict, Any, Generator
from copy import deepcopy
from typing import Any, Dict, Generator, Optional
import sublime


Expand Down
2 changes: 1 addition & 1 deletion plugin/core/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from .logging import exception_log
from .logging import printf
from .types import ClientConfig
from .typing import Generator, List, Optional, Set, Dict, Deque
from .url import parse_uri
from .workspace import enable_in_project, disable_in_project
from abc import ABCMeta
from abc import abstractmethod
from collections import deque
from datetime import datetime, timedelta
from typing import Deque, Dict, Generator, List, Optional, Set
from weakref import WeakSet
import sublime

Expand Down
2 changes: 1 addition & 1 deletion plugin/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .protocol import DiagnosticSeverity
from .protocol import DocumentHighlightKind
from .protocol import SymbolKind
from .typing import Dict, Tuple
from typing import Dict, Tuple
import sublime


Expand Down
2 changes: 1 addition & 1 deletion plugin/core/css.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Optional
import sublime
from .typing import Optional


class CSS:
Expand Down
2 changes: 1 addition & 1 deletion plugin/core/diagnostics_storage.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .protocol import Diagnostic, DiagnosticSeverity, DocumentUri
from .typing import Callable, Iterator, List, Tuple, TypeVar
from .url import parse_uri
from .views import diagnostic_severity
from collections import OrderedDict
from typing import Callable, Iterator, List, Tuple, TypeVar
import functools

ParsedUri = Tuple[str, str]
Expand Down
2 changes: 1 addition & 1 deletion plugin/core/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .protocol import TextEdit
from .protocol import UINT_MAX
from .protocol import WorkspaceEdit
from .typing import List, Dict, Optional, Tuple
from typing import Dict, List, Optional, Tuple
import sublime


Expand Down
2 changes: 1 addition & 1 deletion plugin/core/file_watcher.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .protocol import FileChangeType
from .protocol import WatchKind
from .typing import List, Literal, Optional, Protocol, Tuple, Type, Union
from abc import ABCMeta
from abc import abstractmethod
from typing import List, Literal, Optional, Protocol, Tuple, Type, Union

DEFAULT_KIND = WatchKind.Create | WatchKind.Change | WatchKind.Delete

Expand Down
5 changes: 3 additions & 2 deletions plugin/core/input_handlers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .constants import ST_VERSION
from .typing import Any, Callable, Dict, List, Optional, ParamSpec, Tuple, Union
from .typing import final
from abc import ABCMeta
from abc import abstractmethod
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
from typing import final
from typing_extensions import ParamSpec
import functools
import sublime
import sublime_plugin
Expand Down
2 changes: 1 addition & 1 deletion plugin/core/logging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .typing import Any
from typing import Any
import traceback
import inspect
import sublime
Expand Down
2 changes: 1 addition & 1 deletion plugin/core/message_request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from .protocol import Response
from .protocol import ShowMessageRequestParams
from .sessions import Session
from .typing import Any, Dict, List
from .views import show_lsp_popup
from .views import text2html
from typing import Any, Dict, List
import sublime


Expand Down
4 changes: 2 additions & 2 deletions plugin/core/open.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from .protocol import DocumentUri
from .protocol import Range
from .protocol import UINT_MAX
from .typing import Dict, Tuple, Optional
from .typing import cast
from .url import parse_uri
from .views import range_to_region
from typing import Dict, Optional, Tuple
from typing import cast
from urllib.parse import unquote, urlparse
import os
import re
Expand Down
2 changes: 1 addition & 1 deletion plugin/core/panels.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .types import PANEL_FILE_REGEX
from .types import PANEL_LINE_REGEX
from .typing import Iterable, Optional
from typing import Iterable, Optional
import sublime


Expand Down
2 changes: 1 addition & 1 deletion plugin/core/paths.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .protocol import DocumentUri
from .sessions import Session
from .typing import Iterable, Optional, Tuple
from .views import parse_uri
from pathlib import Path
from typing import Iterable, Optional, Tuple


def simple_path(session: Optional[Session], uri: DocumentUri) -> str:
Expand Down
2 changes: 1 addition & 1 deletion plugin/core/progress.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Optional, Union
import sublime
from .typing import Optional, Union


class ProgressReporter:
Expand Down
2 changes: 1 addition & 1 deletion plugin/core/promise.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .typing import Callable, Generic, List, Optional, Protocol, Tuple, TypeVar, Union
from typing import Callable, Generic, List, Optional, Protocol, Tuple, TypeVar, Union
import functools
import threading

Expand Down
30 changes: 16 additions & 14 deletions plugin/core/protocol.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from .typing import Enum, IntEnum, IntFlag, StrEnum
from .typing import Any, Dict, Generic, Iterable, List, Literal, Mapping, NotRequired, Optional, TypedDict, TypeVar, Union # noqa: E501
from .typing import StrEnum
from enum import IntEnum, IntFlag
from functools import total_ordering
from typing import Any, Dict, Generic, Iterable, List, Literal, Mapping, Optional, TypedDict, TypeVar, Union
from typing_extensions import NotRequired
import sublime

INT_MAX = 2**31 - 1
Expand All @@ -14,7 +16,7 @@
RegExp = str


class SemanticTokenTypes(Enum):
class SemanticTokenTypes(StrEnum):
""" A set of predefined token types. This set is not fixed
an clients can specify additional token types via the
corresponding client capabilities.
Expand Down Expand Up @@ -48,7 +50,7 @@ class SemanticTokenTypes(Enum):
""" @since 3.17.0 """


class SemanticTokenModifiers(Enum):
class SemanticTokenModifiers(StrEnum):
""" A set of predefined token modifiers. This set is not fixed
an clients can specify additional token types via the
corresponding client capabilities.
Expand All @@ -66,7 +68,7 @@ class SemanticTokenModifiers(Enum):
DefaultLibrary = 'defaultLibrary'


class DocumentDiagnosticReportKind(Enum):
class DocumentDiagnosticReportKind(StrEnum):
""" The document diagnostic report kinds.

@since 3.17.0 """
Expand Down Expand Up @@ -167,7 +169,7 @@ class SymbolTag(IntEnum):
""" Render a symbol as obsolete, usually using a strike-out. """


class UniquenessLevel(Enum):
class UniquenessLevel(StrEnum):
""" Moniker uniqueness level to define scope of the moniker.

@since 3.16.0 """
Expand All @@ -183,7 +185,7 @@ class UniquenessLevel(Enum):
""" The moniker is globally unique """


class MonikerKind(Enum):
class MonikerKind(StrEnum):
""" The moniker kind.

@since 3.16.0 """
Expand Down Expand Up @@ -383,7 +385,7 @@ class CodeActionKind(StrEnum):
@since 3.15.0 """


class TraceValues(Enum):
class TraceValues(StrEnum):
Off = 'off'
""" Turn tracing off. """
Messages = 'messages'
Expand All @@ -392,7 +394,7 @@ class TraceValues(Enum):
""" Verbose message tracing. """


class MarkupKind(Enum):
class MarkupKind(StrEnum):
""" Describes the content type that a client supports in various
result literals like `Hover`, `ParameterInfo` or `CompletionItem`.

Expand All @@ -415,7 +417,7 @@ class InlineCompletionTriggerKind(IntEnum):
""" Completion was triggered automatically while editing. """


class PositionEncodingKind(Enum):
class PositionEncodingKind(StrEnum):
""" A set of predefined position encoding kinds.

@since 3.17.0 """
Expand Down Expand Up @@ -517,7 +519,7 @@ class CodeActionTriggerKind(IntEnum):
also be triggered when file content changes. """


class FileOperationPatternKind(Enum):
class FileOperationPatternKind(StrEnum):
""" A pattern kind describing if a glob pattern matches a file a folder or
both.

Expand All @@ -538,7 +540,7 @@ class NotebookCellKind(IntEnum):
""" A code-cell is source code. """


class ResourceOperationKind(Enum):
class ResourceOperationKind(StrEnum):
Create = 'create'
""" Supports creating new files and folders. """
Rename = 'rename'
Expand All @@ -547,7 +549,7 @@ class ResourceOperationKind(Enum):
""" Supports deleting existing files and folders. """


class FailureHandlingKind(Enum):
class FailureHandlingKind(StrEnum):
Abort = 'abort'
""" Applying the workspace change is simply aborted if one of the changes provided
fails. All operations executed before the failing operation stay executed. """
Expand All @@ -569,7 +571,7 @@ class PrepareSupportDefaultBehavior(IntEnum):
according the to language's syntax rule. """


class TokenFormat(Enum):
class TokenFormat(StrEnum):
Relative = 'relative'


Expand Down
2 changes: 1 addition & 1 deletion plugin/core/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from .protocol import LocationLink
from .sessions import AbstractViewListener
from .sessions import Session
from .typing import Optional, Any, Generator, Iterable, List, Union
from .views import first_selection_region
from .views import get_uri_and_position_from_location
from .views import MissingUriError
Expand All @@ -12,6 +11,7 @@
from .windows import WindowManager
from .windows import WindowRegistry
from functools import partial
from typing import Any, Generator, Iterable, List, Optional, Union
import operator
import sublime
import sublime_plugin
Expand Down
Loading