Skip to content

Commit c93a9af

Browse files
committed
Merge branch 'develop' into docstring-hook
2 parents eb3f843 + e9776fd commit c93a9af

23 files changed

+75
-73
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
PYTHON_VERSION: ['3.8']
20+
PYTHON_VERSION: ['3.9']
2121
timeout-minutes: 10
2222
steps:
2323
- uses: actions/cache@v1

.github/workflows/static.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ jobs:
3030
- uses: actions/checkout@v4
3131
- uses: actions/setup-python@v5
3232
with:
33-
# TODO: check with Python 3, but need to fix the
34-
# errors first
35-
python-version: '3.8'
33+
python-version: '3.9'
3634
architecture: 'x64'
3735
- run: python -m pip install --upgrade pip setuptools jsonschema
3836
# If we don't install pycodestyle, pylint will throw an unused-argument error in pylsp/plugins/pycodestyle_lint.py:72

.github/workflows/test-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
strategy:
2525
fail-fast: false
2626
matrix:
27-
PYTHON_VERSION: ['3.10', '3.9', '3.8']
27+
PYTHON_VERSION: ['3.11', '3.10', '3.9']
2828
timeout-minutes: 10
2929
steps:
3030
- uses: actions/cache@v4

.github/workflows/test-mac.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
strategy:
2525
fail-fast: false
2626
matrix:
27-
PYTHON_VERSION: ['3.10', '3.9', '3.8']
27+
PYTHON_VERSION: ['3.11', '3.10', '3.9']
2828
timeout-minutes: 10
2929
steps:
3030
- uses: actions/cache@v4

.github/workflows/test-win.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
strategy:
2525
fail-fast: false
2626
matrix:
27-
PYTHON_VERSION: ['3.10', '3.9', '3.8']
27+
PYTHON_VERSION: ['3.11', '3.10', '3.9']
2828
timeout-minutes: 10
2929
steps:
3030
- uses: actions/cache@v4

pylsp/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
start_ws_lang_server,
2121
)
2222

23-
LOG_FORMAT = "%(asctime)s {0} - %(levelname)s - %(name)s - %(message)s".format(
23+
LOG_FORMAT = "%(asctime)s {} - %(levelname)s - %(name)s - %(message)s".format(
2424
time.localtime().tm_zone
2525
)
2626

@@ -98,7 +98,7 @@ def _configure_logger(verbose=0, log_config=None, log_file=None) -> None:
9898
root_logger = logging.root
9999

100100
if log_config:
101-
with open(log_config, "r", encoding="utf-8") as f:
101+
with open(log_config, encoding="utf-8") as f:
102102
logging.config.dictConfig(json.load(f))
103103
else:
104104
formatter = logging.Formatter(LOG_FORMAT)

pylsp/_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
import threading
1313
import time
14-
from typing import List, Optional
14+
from typing import Optional
1515

1616
import docstring_to_markdown
1717
import jedi
@@ -80,7 +80,7 @@ def find_parents(root, path, names):
8080
8181
Args:
8282
path (str): The file path to start searching up from.
83-
names (List[str]): The file/directory names to look for.
83+
names (list[str]): The file/directory names to look for.
8484
root (str): The directory at which to stop recursing upwards.
8585
8686
Note:
@@ -200,7 +200,7 @@ def wrap_signature(signature):
200200
SERVER_SUPPORTED_MARKUP_KINDS = {"markdown", "plaintext"}
201201

202202

203-
def choose_markup_kind(client_supported_markup_kinds: List[str]):
203+
def choose_markup_kind(client_supported_markup_kinds: list[str]):
204204
"""Choose a markup kind supported by both client and the server.
205205
206206
This gives priority to the markup kinds provided earlier on the client preference list.
@@ -316,7 +316,7 @@ def convert_signatures_to_markdown(signatures: List[str], config: dict) -> str:
316316
def format_docstring(
317317
contents: str,
318318
markup_kind: str,
319-
signatures: Optional[List[str]] = None,
319+
signatures: Optional[list[str]] = None,
320320
signature_config: Optional[dict] = None,
321321
):
322322
"""Transform the provided docstring into a MarkupContent object.

pylsp/config/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
import logging
55
import sys
6+
from collections.abc import Mapping, Sequence
67
from functools import lru_cache
7-
from typing import List, Mapping, Sequence, Union
8+
from typing import Union
89

910
import pluggy
1011
from pluggy._hooks import HookImpl
@@ -32,7 +33,7 @@ def _hookexec(
3233
methods: Sequence[HookImpl],
3334
kwargs: Mapping[str, object],
3435
firstresult: bool,
35-
) -> Union[object, List[object]]:
36+
) -> Union[object, list[object]]:
3637
# called from all hookcaller instances.
3738
# enable_tracing will set its own wrapping function at self._inner_hookexec
3839
try:

pylsp/plugins/_resolvers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def resolve(self, completion):
8888
def format_label(completion, sig):
8989
if sig and completion.type in ("function", "method"):
9090
params = ", ".join(param.name for param in sig[0].params)
91-
label = "{}({})".format(completion.name, params)
91+
label = f"{completion.name}({params})"
9292
return label
9393
return completion.name
9494

@@ -115,7 +115,7 @@ def format_snippet(completion, sig):
115115
snippet_completion["insertTextFormat"] = lsp.InsertTextFormat.Snippet
116116
snippet = completion.name + "("
117117
for i, param in enumerate(positional_args):
118-
snippet += "${%s:%s}" % (i + 1, param.name)
118+
snippet += "${{{}:{}}}".format(i + 1, param.name)
119119
if i < len(positional_args) - 1:
120120
snippet += ", "
121121
snippet += ")$0"

pylsp/plugins/_rope_task_handle.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

33
import logging
4-
from typing import Callable, ContextManager, List, Optional, Sequence
4+
from collections.abc import Sequence
5+
from typing import Callable, ContextManager
56

67
from rope.base.taskhandle import BaseJobSet, BaseTaskHandle
78

@@ -19,13 +20,13 @@ class PylspJobSet(BaseJobSet):
1920
_report_iter: ContextManager
2021
job_name: str = ""
2122

22-
def __init__(self, count: Optional[int], report_iter: ContextManager) -> None:
23+
def __init__(self, count: int | None, report_iter: ContextManager) -> None:
2324
if count is not None:
2425
self.count = count
2526
self._reporter = report_iter.__enter__()
2627
self._report_iter = report_iter
2728

28-
def started_job(self, name: Optional[str]) -> None:
29+
def started_job(self, name: str | None) -> None:
2930
if name:
3031
self.job_name = name
3132

@@ -42,7 +43,7 @@ def finished_job(self) -> None:
4243
def check_status(self) -> None:
4344
pass
4445

45-
def get_percent_done(self) -> Optional[float]:
46+
def get_percent_done(self) -> float | None:
4647
if self.count == 0:
4748
return 0
4849
return (self.done / self.count) * 100
@@ -66,8 +67,8 @@ def _report(self) -> None:
6667

6768
class PylspTaskHandle(BaseTaskHandle):
6869
name: str
69-
observers: List
70-
job_sets: List[PylspJobSet]
70+
observers: list
71+
job_sets: list[PylspJobSet]
7172
stopped: bool
7273
workspace: Workspace
7374
_report: Callable[[str, str], None]
@@ -77,7 +78,7 @@ def __init__(self, workspace: Workspace) -> None:
7778
self.job_sets = []
7879
self.observers = []
7980

80-
def create_jobset(self, name="JobSet", count: Optional[int] = None):
81+
def create_jobset(self, name="JobSet", count: int | None = None):
8182
report_iter = self.workspace.report_progress(
8283
name, None, None, skip_token_initialization=True
8384
)
@@ -89,7 +90,7 @@ def create_jobset(self, name="JobSet", count: Optional[int] = None):
8990
def stop(self) -> None:
9091
pass
9192

92-
def current_jobset(self) -> Optional[BaseJobSet]:
93+
def current_jobset(self) -> BaseJobSet | None:
9394
pass
9495

9596
def add_observer(self) -> None:

pylsp/plugins/definition.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import logging
6-
from typing import TYPE_CHECKING, Any, Dict, List
6+
from typing import TYPE_CHECKING, Any
77

88
import jedi
99

@@ -23,7 +23,7 @@
2323

2424

2525
def _resolve_definition(
26-
maybe_defn: Name, script: Script, settings: Dict[str, Any]
26+
maybe_defn: Name, script: Script, settings: dict[str, Any]
2727
) -> Name:
2828
for _ in range(MAX_JEDI_GOTO_HOPS):
2929
if maybe_defn.is_definition() or maybe_defn.module_path != script.path:
@@ -43,8 +43,8 @@ def _resolve_definition(
4343

4444
@hookimpl
4545
def pylsp_definitions(
46-
config: Config, document: Document, position: Dict[str, int]
47-
) -> List[Dict[str, Any]]:
46+
config: Config, document: Document, position: dict[str, int]
47+
) -> list[dict[str, Any]]:
4848
settings = config.plugin_settings("jedi_definition")
4949
code_position = _utils.position_to_jedi_linecolumn(document, position)
5050
script = document.jedi_script(use_document_path=True)

pylsp/plugins/flake8_lint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def run_flake8(flake8_executable, args, document, source):
135135
cmd = [flake8_executable]
136136
cmd.extend(args)
137137
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, **popen_kwargs)
138-
except IOError:
138+
except OSError:
139139
log.debug(
140140
"Can't execute %s. Trying with '%s -m flake8'",
141141
flake8_executable,
@@ -165,9 +165,9 @@ def build_args(options):
165165
arg = "--{}={}".format(arg_name, ",".join(arg_val))
166166
elif isinstance(arg_val, bool):
167167
if arg_val:
168-
arg = "--{}".format(arg_name)
168+
arg = f"--{arg_name}"
169169
else:
170-
arg = "--{}={}".format(arg_name, arg_val)
170+
arg = f"--{arg_name}={arg_val}"
171171
args.append(arg)
172172
return args
173173

pylsp/plugins/pylint_lint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def _run_pylint_stdio(pylint_executable, document, flags):
287287
cmd.extend(flags)
288288
cmd.extend(["--from-stdin", document.path])
289289
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
290-
except IOError:
290+
except OSError:
291291
log.debug("Can't execute %s. Trying with 'python -m pylint'", pylint_executable)
292292
cmd = [sys.executable, "-m", "pylint"]
293293
cmd.extend(flags)

pylsp/plugins/rope_autoimport.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import logging
44
import threading
5-
from typing import Any, Dict, Generator, List, Optional, Set, Union
5+
from collections.abc import Generator
6+
from typing import Any, Optional, Union
67

78
import parso
89
from jedi import Script
@@ -36,7 +37,7 @@ def reload_cache(
3637
self,
3738
config: Config,
3839
workspace: Workspace,
39-
files: Optional[List[Document]] = None,
40+
files: Optional[list[Document]] = None,
4041
single_thread: Optional[bool] = True,
4142
):
4243
if self.is_blocked():
@@ -45,7 +46,7 @@ def reload_cache(
4546
memory: bool = config.plugin_settings("rope_autoimport").get("memory", False)
4647
rope_config = config.settings().get("rope", {})
4748
autoimport = workspace._rope_autoimport(rope_config, memory)
48-
resources: Optional[List[Resource]] = (
49+
resources: Optional[list[Resource]] = (
4950
None
5051
if files is None
5152
else [document._rope_resource(rope_config) for document in files]
@@ -65,7 +66,7 @@ def _reload_cache(
6566
self,
6667
workspace: Workspace,
6768
autoimport: AutoImport,
68-
resources: Optional[List[Resource]] = None,
69+
resources: Optional[list[Resource]] = None,
6970
) -> None:
7071
task_handle = PylspTaskHandle(workspace)
7172
autoimport.generate_cache(task_handle=task_handle, resources=resources)
@@ -76,7 +77,7 @@ def is_blocked(self):
7677

7778

7879
@hookimpl
79-
def pylsp_settings() -> Dict[str, Dict[str, Dict[str, Any]]]:
80+
def pylsp_settings() -> dict[str, dict[str, dict[str, Any]]]:
8081
# Default rope_completion to disabled
8182
return {
8283
"plugins": {
@@ -180,13 +181,13 @@ def _handle_argument(node: NodeOrLeaf, word_node: tree.Leaf):
180181

181182

182183
def _process_statements(
183-
suggestions: List[SearchResult],
184+
suggestions: list[SearchResult],
184185
doc_uri: str,
185186
word: str,
186187
autoimport: AutoImport,
187188
document: Document,
188189
feature: str = "completions",
189-
) -> Generator[Dict[str, Any], None, None]:
190+
) -> Generator[dict[str, Any], None, None]:
190191
for suggestion in suggestions:
191192
insert_line = autoimport.find_insertion_line(document.source) - 1
192193
start = {"line": insert_line, "character": 0}
@@ -220,7 +221,7 @@ def _process_statements(
220221
raise ValueError(f"Unknown feature: {feature}")
221222

222223

223-
def get_names(script: Script) -> Set[str]:
224+
def get_names(script: Script) -> set[str]:
224225
"""Get all names to ignore from the current file."""
225226
raw_names = script.get_names(definitions=True)
226227
log.debug(raw_names)
@@ -233,7 +234,7 @@ def pylsp_completions(
233234
workspace: Workspace,
234235
document: Document,
235236
position,
236-
ignored_names: Union[Set[str], None],
237+
ignored_names: Union[set[str], None],
237238
):
238239
"""Get autoimport suggestions."""
239240
if (
@@ -251,7 +252,7 @@ def pylsp_completions(
251252
word = word_node.value
252253
log.debug(f"autoimport: searching for word: {word}")
253254
rope_config = config.settings(document_path=document.path).get("rope", {})
254-
ignored_names: Set[str] = ignored_names or get_names(
255+
ignored_names: set[str] = ignored_names or get_names(
255256
document.jedi_script(use_document_path=True)
256257
)
257258
autoimport = workspace._rope_autoimport(rope_config)
@@ -303,9 +304,9 @@ def pylsp_code_actions(
303304
config: Config,
304305
workspace: Workspace,
305306
document: Document,
306-
range: Dict,
307-
context: Dict,
308-
) -> List[Dict]:
307+
range: dict,
308+
context: dict,
309+
) -> list[dict]:
309310
"""
310311
Provide code actions through rope.
311312
@@ -317,9 +318,9 @@ def pylsp_code_actions(
317318
Current workspace.
318319
document : pylsp.workspace.Document
319320
Document to apply code actions on.
320-
range : Dict
321+
range : dict
321322
Range argument given by pylsp. Not used here.
322-
context : Dict
323+
context : dict
323324
CodeActionContext given as dict.
324325
325326
Returns

pylsp/plugins/rope_completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _resolve_completion(completion, data, markup_kind):
2222
except Exception as e:
2323
log.debug("Failed to resolve Rope completion: %s", e)
2424
doc = ""
25-
completion["detail"] = "{0} {1}".format(data.scope or "", data.name)
25+
completion["detail"] = "{} {}".format(data.scope or "", data.name)
2626
completion["documentation"] = doc
2727
return completion
2828

0 commit comments

Comments
 (0)