Skip to content

Commit 8caea2a

Browse files
committed
chore(ruff) Automated fixes for Python 3.9
ruff check . --select ALL --fix --unsafe-fixes --preview --show-fixes --ignore T201 --ignore PT014 --ignore RUF100; ruff format .; Fixed 174 errors: - conftest.py: 3 × UP006 (non-pep585-annotation) - docs/_ext/aafig.py: 7 × UP006 (non-pep585-annotation) 2 × RUF052 (used-dummy-variable) - docs/conf.py: 6 × UP006 (non-pep585-annotation) - src/tmuxp/_internal/config_reader.py: 5 × UP006 (non-pep585-annotation) 2 × TC006 (runtime-cast-value) - src/tmuxp/_internal/types.py: 3 × UP006 (non-pep585-annotation) 1 × F401 (unused-import) - src/tmuxp/cli/__init__.py: 1 × UP006 (non-pep585-annotation) - src/tmuxp/cli/debug_info.py: 2 × UP006 (non-pep585-annotation) - src/tmuxp/cli/freeze.py: 2 × UP006 (non-pep585-annotation) 1 × RUF052 (used-dummy-variable) 1 × TC006 (runtime-cast-value) - src/tmuxp/cli/import_config.py: 2 × UP006 (non-pep585-annotation) - src/tmuxp/cli/load.py: 3 × UP006 (non-pep585-annotation) - src/tmuxp/cli/utils.py: 6 × UP006 (non-pep585-annotation) 5 × RUF052 (used-dummy-variable) - src/tmuxp/log.py: 1 × UP006 (non-pep585-annotation) - src/tmuxp/plugin.py: 5 × UP006 (non-pep585-annotation) - src/tmuxp/shell.py: 7 × UP006 (non-pep585-annotation) - src/tmuxp/workspace/builder.py: 8 × UP006 (non-pep585-annotation) - src/tmuxp/workspace/finders.py: 4 × UP006 (non-pep585-annotation) 1 × PLC1802 (len-test) - src/tmuxp/workspace/freezer.py: 5 × UP006 (non-pep585-annotation) - src/tmuxp/workspace/importers.py: 4 × UP006 (non-pep585-annotation) - src/tmuxp/workspace/loader.py: 6 × UP006 (non-pep585-annotation) - tests/cli/test_cli.py: 1 × UP006 (non-pep585-annotation) - tests/cli/test_convert.py: 2 × UP006 (non-pep585-annotation) 1 × F401 (unused-import) - tests/cli/test_freeze.py: 4 × UP006 (non-pep585-annotation) - tests/cli/test_import.py: 5 × UP006 (non-pep585-annotation) 1 × F401 (unused-import) - tests/cli/test_load.py: 16 × UP006 (non-pep585-annotation) - tests/cli/test_shell.py: 19 × UP006 (non-pep585-annotation) - tests/fixtures/pluginsystem/partials/_types.py: 3 × UP006 (non-pep585-annotation) 1 × F401 (unused-import) - tests/fixtures/utils.py: 2 × RUF052 (used-dummy-variable) - tests/fixtures/workspace/expand1.py: 1 × UP006 (non-pep585-annotation) - tests/fixtures/workspace/shell_command_before.py: 2 × UP006 (non-pep585-annotation) - tests/workspace/test_builder.py: 11 × RUF052 (used-dummy-variable) 2 × UP006 (non-pep585-annotation) - tests/workspace/test_config.py: 1 × UP006 (non-pep585-annotation) - tests/workspace/test_import_teamocil.py: 7 × UP006 (non-pep585-annotation) - tests/workspace/test_import_tmuxinator.py: 2 × UP006 (non-pep585-annotation) Found 1371 errors (174 fixed, 1197 remaining). 2 files reformatted, 97 files left unchanged
1 parent ac61dfb commit 8caea2a

33 files changed

+186
-192
lines changed

conftest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def monkeypatch_plugin_test_packages(monkeypatch: pytest.MonkeyPatch) -> None:
8484

8585

8686
@pytest.fixture
87-
def session_params(session_params: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
87+
def session_params(session_params: dict[str, t.Any]) -> dict[str, t.Any]:
8888
"""Terminal-friendly tmuxp session_params for dimensions."""
8989
session_params.update({"x": 800, "y": 600})
9090
return session_params
@@ -99,7 +99,7 @@ def socket_name(request: pytest.FixtureRequest) -> str:
9999
@pytest.fixture(autouse=True)
100100
def add_doctest_fixtures(
101101
request: pytest.FixtureRequest,
102-
doctest_namespace: t.Dict[str, t.Any],
102+
doctest_namespace: dict[str, t.Any],
103103
tmp_path: pathlib.Path,
104104
) -> None:
105105
"""Harness pytest fixtures to doctests namespace."""

docs/_ext/aafig.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040

4141

4242
def merge_dict(
43-
dst: t.Dict[str, t.Optional[str]],
44-
src: t.Dict[str, t.Optional[str]],
45-
) -> t.Dict[str, t.Optional[str]]:
43+
dst: dict[str, t.Optional[str]],
44+
src: dict[str, t.Optional[str]],
45+
) -> dict[str, t.Optional[str]]:
4646
for k, v in src.items():
4747
if k not in dst:
4848
dst[k] = v
@@ -51,15 +51,15 @@ def merge_dict(
5151

5252
def get_basename(
5353
text: str,
54-
options: t.Dict[str, str],
54+
options: dict[str, str],
5555
prefix: t.Optional[str] = "aafig",
5656
) -> str:
5757
options = options.copy()
5858
if "format" in options:
5959
del options["format"]
6060
hashkey = text + str(options)
61-
_id = sha(hashkey.encode("utf-8")).hexdigest()
62-
return f"{prefix}-{_id}"
61+
id_ = sha(hashkey.encode("utf-8")).hexdigest()
62+
return f"{prefix}-{id_}"
6363

6464

6565
class AafigError(SphinxError):
@@ -83,7 +83,7 @@ class AafigDirective(images.Image): # type:ignore
8383
option_spec = images.Image.option_spec.copy()
8484
option_spec.update(own_option_spec)
8585

86-
def run(self) -> t.List[nodes.Node]:
86+
def run(self) -> list[nodes.Node]:
8787
aafig_options = {}
8888
own_options_keys = [self.own_option_spec.keys(), "scale"]
8989
for k, v in self.options.items():
@@ -120,13 +120,13 @@ def render_aafig_images(app: "Sphinx", doctree: nodes.Node) -> None:
120120
continue
121121
options = img.aafig["options"]
122122
text = img.aafig["text"]
123-
_format = app.builder.format
123+
format_ = app.builder.format
124124
merge_dict(options, app.builder.config.aafig_default_options)
125-
if _format in format_map:
126-
options["format"] = format_map[_format]
125+
if format_ in format_map:
126+
options["format"] = format_map[format_]
127127
else:
128128
logger.warning(
129-
f'unsupported builder format "{_format}", please '
129+
f'unsupported builder format "{format_}", please '
130130
"add a custom entry in aafig_format config "
131131
"option for this builder",
132132
)
@@ -159,8 +159,8 @@ def __init__(self, *args: object, **kwargs: object) -> None:
159159
def render_aafigure(
160160
app: "Sphinx",
161161
text: str,
162-
options: t.Dict[str, str],
163-
) -> t.Tuple[str, str, t.Optional[str], t.Optional[str]]:
162+
options: dict[str, str],
163+
) -> tuple[str, str, t.Optional[str], t.Optional[str]]:
164164
"""Render an ASCII art figure into the requested format output file."""
165165
if aafigure is None:
166166
raise AafigureNotInstalled

docs/conf.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
sys.path.insert(0, str(cwd / "_ext"))
2323

2424
# package data
25-
about: t.Dict[str, str] = {}
25+
about: dict[str, str] = {}
2626
with (src_root / "tmuxp" / "__about__.py").open() as fp:
2727
exec(fp.read(), about)
2828

@@ -73,8 +73,8 @@
7373
html_static_path = ["_static"]
7474
html_favicon = "_static/favicon.ico"
7575
html_theme = "furo"
76-
html_theme_path: t.List[str] = []
77-
html_theme_options: t.Dict[str, t.Union[str, t.List[t.Dict[str, str]]]] = {
76+
html_theme_path: list[str] = []
77+
html_theme_options: dict[str, t.Union[str, list[dict[str, str]]]] = {
7878
"light_logo": "img/tmuxp.svg",
7979
"dark_logo": "img/tmuxp.svg",
8080
"footer_icons": [
@@ -143,7 +143,7 @@
143143
}
144144

145145

146-
def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]:
146+
def linkcode_resolve(domain: str, info: dict[str, str]) -> t.Union[None, str]:
147147
"""
148148
Determine the URL corresponding to Python object.
149149

src/tmuxp/_internal/config_reader.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
FormatLiteral = t.Literal["json", "yaml"]
1313

14-
RawConfigData: TypeAlias = t.Dict[t.Any, t.Any]
14+
RawConfigData: TypeAlias = dict[t.Any, t.Any]
1515

1616

1717
class ConfigReader:
@@ -28,7 +28,7 @@ def __init__(self, content: "RawConfigData") -> None:
2828
self.content = content
2929

3030
@staticmethod
31-
def _load(fmt: "FormatLiteral", content: str) -> t.Dict[str, t.Any]:
31+
def _load(fmt: "FormatLiteral", content: str) -> dict[str, t.Any]:
3232
"""Load raw config data and directly return it.
3333
3434
>>> ConfigReader._load("json", '{ "session_name": "my session" }')
@@ -39,14 +39,14 @@ def _load(fmt: "FormatLiteral", content: str) -> t.Dict[str, t.Any]:
3939
"""
4040
if fmt == "yaml":
4141
return t.cast(
42-
t.Dict[str, t.Any],
42+
"dict[str, t.Any]",
4343
yaml.load(
4444
content,
4545
Loader=yaml.SafeLoader,
4646
),
4747
)
4848
if fmt == "json":
49-
return t.cast(t.Dict[str, t.Any], json.loads(content))
49+
return t.cast("dict[str, t.Any]", json.loads(content))
5050
msg = f"{fmt} not supported in configuration"
5151
raise NotImplementedError(msg)
5252

@@ -74,7 +74,7 @@ def load(cls, fmt: "FormatLiteral", content: str) -> "ConfigReader":
7474
)
7575

7676
@classmethod
77-
def _from_file(cls, path: pathlib.Path) -> t.Dict[str, t.Any]:
77+
def _from_file(cls, path: pathlib.Path) -> dict[str, t.Any]:
7878
r"""Load data from file path directly to dictionary.
7979
8080
**YAML file**

src/tmuxp/_internal/types.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@
1010
...
1111
"""
1212

13-
import typing as t
14-
1513
from typing_extensions import NotRequired, TypedDict
1614

1715

1816
class PluginConfigSchema(TypedDict):
1917
plugin_name: NotRequired[str]
2018
tmux_min_version: NotRequired[str]
2119
tmux_max_version: NotRequired[str]
22-
tmux_version_incompatible: NotRequired[t.List[str]]
20+
tmux_version_incompatible: NotRequired[list[str]]
2321
libtmux_min_version: NotRequired[str]
2422
libtmux_max_version: NotRequired[str]
25-
libtmux_version_incompatible: NotRequired[t.List[str]]
23+
libtmux_version_incompatible: NotRequired[list[str]]
2624
tmuxp_min_version: NotRequired[str]
2725
tmuxp_max_version: NotRequired[str]
28-
tmuxp_version_incompatible: NotRequired[t.List[str]]
26+
tmuxp_version_incompatible: NotRequired[list[str]]

src/tmuxp/cli/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class CLINamespace(argparse.Namespace):
118118
ns = CLINamespace()
119119

120120

121-
def cli(_args: t.Optional[t.List[str]] = None) -> None:
121+
def cli(_args: t.Optional[list[str]] = None) -> None:
122122
"""Manage tmux sessions.
123123
124124
Pass the "--help" argument to any command to see detailed help.

src/tmuxp/cli/debug_info.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def command_debug_info(
3131
) -> None:
3232
"""Entrypoint for ``tmuxp debug-info`` to print debug info to submit with issues."""
3333

34-
def prepend_tab(strings: t.List[str]) -> t.List[str]:
34+
def prepend_tab(strings: list[str]) -> list[str]:
3535
"""Prepend tab to strings in list."""
3636
return [f"\t{x}" for x in strings]
3737

src/tmuxp/cli/freeze.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def command_freeze(
165165
dest = os.path.abspath(os.path.relpath(os.path.expanduser(dest)))
166166
workspace_format = args.workspace_format
167167

168-
valid_workspace_formats: t.List[CLIOutputFormatLiteral] = ["json", "yaml"]
168+
valid_workspace_formats: list[CLIOutputFormatLiteral] = ["json", "yaml"]
169169

170170
def is_valid_ext(stem: t.Optional[str]) -> "TypeGuard[CLIOutputFormatLiteral]":
171171
return stem in valid_workspace_formats
@@ -184,15 +184,15 @@ def extract_workspace_format(
184184

185185
workspace_format = extract_workspace_format(dest)
186186
if not is_valid_ext(workspace_format):
187-
_workspace_format = prompt_choices(
187+
workspace_format_ = prompt_choices(
188188
"Couldn't ascertain one of [{}] from file name. Convert to".format(
189189
", ".join(valid_workspace_formats),
190190
),
191-
choices=t.cast(t.List[str], valid_workspace_formats),
191+
choices=t.cast("list[str]", valid_workspace_formats),
192192
default="yaml",
193193
)
194-
assert is_valid_ext(_workspace_format)
195-
workspace_format = _workspace_format
194+
assert is_valid_ext(workspace_format_)
195+
workspace_format = workspace_format_
196196

197197
if workspace_format == "yaml":
198198
workspace = configparser.dump(

src/tmuxp/cli/import_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def create_import_subparser(
128128
class ImportConfigFn(t.Protocol):
129129
"""Typing for import configuration callback function."""
130130

131-
def __call__(self, workspace_dict: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
131+
def __call__(self, workspace_dict: dict[str, t.Any]) -> dict[str, t.Any]:
132132
"""Execute tmuxp import function."""
133133
...
134134

src/tmuxp/cli/load.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class OptionOverrides(TypedDict):
3636
class CLILoadNamespace(argparse.Namespace):
3737
"""Typed :class:`argparse.Namespace` for tmuxp load command."""
3838

39-
workspace_files: t.List[str]
39+
workspace_files: list[str]
4040
socket_name: t.Optional[str]
4141
socket_path: t.Optional[str]
4242
tmux_config_file: t.Optional[str]
@@ -47,7 +47,7 @@ class CLILoadNamespace(argparse.Namespace):
4747
log_file: t.Optional[str]
4848

4949

50-
def load_plugins(session_config: t.Dict[str, t.Any]) -> t.List[t.Any]:
50+
def load_plugins(session_config: dict[str, t.Any]) -> list[t.Any]:
5151
"""Load and return plugins in workspace."""
5252
plugins = []
5353
if "plugins" in session_config:

src/tmuxp/cli/utils.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
if t.TYPE_CHECKING:
1010
from typing_extensions import TypeAlias
1111

12-
CLIColour: TypeAlias = t.Union[int, t.Tuple[int, int, int], str]
12+
CLIColour: TypeAlias = t.Union[int, tuple[int, int, int], str]
1313

1414

1515
logger = logging.getLogger(__name__)
@@ -56,10 +56,10 @@ def prompt(
5656
`flask-script <https://github.com/techniq/flask-script>`_. See the
5757
`flask-script license <https://github.com/techniq/flask-script/blob/master/LICENSE>`_.
5858
"""
59-
_prompt = name + ((default and f" [{default}]") or "")
60-
_prompt += (name.endswith("?") and " ") or ": "
59+
prompt_ = name + ((default and f" [{default}]") or "")
60+
prompt_ += (name.endswith("?") and " ") or ": "
6161
while True:
62-
rv = input(_prompt) or default
62+
rv = input(prompt_) or default
6363
try:
6464
if value_proc is not None and callable(value_proc):
6565
assert isinstance(rv, str)
@@ -106,11 +106,11 @@ def prompt_bool(
106106
else:
107107
prompt_choice = "y/N"
108108

109-
_prompt = name + f" [{prompt_choice}]"
110-
_prompt += (name.endswith("?") and " ") or ": "
109+
prompt_ = name + f" [{prompt_choice}]"
110+
prompt_ += (name.endswith("?") and " ") or ": "
111111

112112
while True:
113-
rv = input(_prompt)
113+
rv = input(prompt_)
114114
if not rv:
115115
return default
116116
if rv.lower() in yes_choices:
@@ -126,7 +126,7 @@ def prompt_yes_no(name: str, default: bool = True) -> bool:
126126

127127
def prompt_choices(
128128
name: str,
129-
choices: t.Union[t.List[str], t.Tuple[str, str]],
129+
choices: t.Union[list[str], tuple[str, str]],
130130
default: t.Optional[str] = None,
131131
no_choice: t.Sequence[str] = ("none",),
132132
) -> t.Optional[str]:
@@ -148,16 +148,16 @@ def prompt_choices(
148148
-------
149149
str
150150
"""
151-
_choices: t.List[str] = []
152-
options: t.List[str] = []
151+
choices_: list[str] = []
152+
options: list[str] = []
153153

154154
for choice in choices:
155155
if isinstance(choice, str):
156156
options.append(choice)
157157
elif isinstance(choice, tuple):
158158
options.append(f"{choice} [{choice[0]}]")
159159
choice = choice[0]
160-
_choices.append(choice)
160+
choices_.append(choice)
161161

162162
while True:
163163
rv = prompt(name + " - ({})".format(", ".join(options)), default=default)
@@ -166,7 +166,7 @@ def prompt_choices(
166166
rv = rv.lower()
167167
if rv in no_choice:
168168
return None
169-
if rv in _choices:
169+
if rv in choices_:
170170
return rv
171171

172172

@@ -201,7 +201,7 @@ def strip_ansi(value: str) -> str:
201201

202202

203203
def _interpret_color(
204-
color: t.Union[int, t.Tuple[int, int, int], str],
204+
color: t.Union[int, tuple[int, int, int], str],
205205
offset: int = 0,
206206
) -> str:
207207
if isinstance(color, int):

src/tmuxp/log.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def format(self, record: logging.LogRecord) -> str:
135135

136136

137137
def debug_log_template(
138-
self: t.Type[logging.Formatter],
138+
self: type[logging.Formatter],
139139
record: logging.LogRecord,
140140
stylized: t.Optional[bool] = False,
141141
**kwargs: t.Any,

src/tmuxp/plugin.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class VersionConstraints(TypedDict):
4141
version: t.Union[Version, str]
4242
vmin: str
4343
vmax: t.Optional[str]
44-
incompatible: t.List[t.Union[t.Any, str]]
44+
incompatible: list[t.Union[t.Any, str]]
4545

4646
class TmuxpPluginVersionConstraints(TypedDict):
4747
"""Version constraints for a tmuxp plugin."""
@@ -57,13 +57,13 @@ class Config(t.TypedDict):
5757
plugin_name: str
5858
tmux_min_version: str
5959
tmux_max_version: t.Optional[str]
60-
tmux_version_incompatible: t.Optional[t.List[str]]
60+
tmux_version_incompatible: t.Optional[list[str]]
6161
libtmux_min_version: str
6262
libtmux_max_version: t.Optional[str]
63-
libtmux_version_incompatible: t.Optional[t.List[str]]
63+
libtmux_version_incompatible: t.Optional[list[str]]
6464
tmuxp_min_version: str
6565
tmuxp_max_version: t.Optional[str]
66-
tmuxp_version_incompatible: t.Optional[t.List[str]]
66+
tmuxp_version_incompatible: t.Optional[list[str]]
6767

6868

6969
DEFAULT_CONFIG: "Config" = {
@@ -200,7 +200,7 @@ def _pass_version_check(
200200
version: t.Union[str, Version],
201201
vmin: str,
202202
vmax: t.Optional[str],
203-
incompatible: t.List[t.Union[t.Any, str]],
203+
incompatible: list[t.Union[t.Any, str]],
204204
) -> bool:
205205
"""Provide affirmative if version compatibility is correct."""
206206
if vmin and version < Version(vmin):

0 commit comments

Comments
 (0)