Skip to content

Commit 627c4ca

Browse files
committed
Modernize type hints to Python 3.10+ syntax using ruff
1 parent c3ba6fd commit 627c4ca

19 files changed

+220
-236
lines changed

src/mxdev/config.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ def to_bool(value):
1717

1818

1919
class Configuration:
20-
settings: typing.Dict[str, str]
21-
overrides: typing.Dict[str, str]
22-
ignore_keys: typing.List[str]
23-
packages: typing.Dict[str, typing.Dict[str, str]]
24-
hooks: typing.Dict[str, typing.Dict[str, str]]
20+
settings: dict[str, str]
21+
overrides: dict[str, str]
22+
ignore_keys: list[str]
23+
packages: dict[str, dict[str, str]]
24+
hooks: dict[str, dict[str, str]]
2525

2626
def __init__(
2727
self,
2828
mxini: str,
29-
override_args: typing.Dict = {},
30-
hooks: typing.List["Hook"] = [],
29+
override_args: dict = {},
30+
hooks: list["Hook"] = [],
3131
) -> None:
3232
logger.debug("Read configuration")
3333
data = read_with_included(mxini)
@@ -164,9 +164,9 @@ def out_constraints(self) -> str:
164164
return self.settings.get("constraints-out", "constraints-mxdev.txt")
165165

166166
@property
167-
def package_keys(self) -> typing.List[str]:
167+
def package_keys(self) -> list[str]:
168168
return [k.lower() for k in self.packages]
169169

170170
@property
171-
def override_keys(self) -> typing.List[str]:
171+
def override_keys(self) -> list[str]:
172172
return [k.lower() for k in self.overrides]

src/mxdev/hooks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def load_hooks() -> list:
3030
return [ep.load()() for ep in load_eps_by_group("mxdev") if ep.name == "hook"]
3131

3232

33-
def read_hooks(state: State, hooks: typing.List[Hook]) -> None:
33+
def read_hooks(state: State, hooks: list[Hook]) -> None:
3434
for hook in hooks:
3535
hook.read(state)
3636

3737

38-
def write_hooks(state: State, hooks: typing.List[Hook]) -> None:
38+
def write_hooks(state: State, hooks: list[Hook]) -> None:
3939
for hook in hooks:
4040
hook.write(state)

src/mxdev/including.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111

1212
def resolve_dependencies(
13-
file_or_url: typing.Union[str, Path],
13+
file_or_url: str | Path,
1414
tmpdir: str,
1515
http_parent=None,
16-
) -> typing.List[Path]:
16+
) -> list[Path]:
1717
"""Resolve dependencies of a file or url
1818
1919
The result is a list of Path objects, starting with the
@@ -69,7 +69,7 @@ def resolve_dependencies(
6969
return file_list
7070

7171

72-
def read_with_included(file_or_url: typing.Union[str, Path]) -> ConfigParser:
72+
def read_with_included(file_or_url: str | Path) -> ConfigParser:
7373
"""Read a file or url and include all referenced files,
7474
7575
Parse the result as a ConfigParser and return it.

src/mxdev/processing.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
def process_line(
1515
line: str,
16-
package_keys: typing.List[str],
17-
override_keys: typing.List[str],
18-
ignore_keys: typing.List[str],
16+
package_keys: list[str],
17+
override_keys: list[str],
18+
ignore_keys: list[str],
1919
variety: str,
20-
) -> typing.Tuple[typing.List[str], typing.List[str]]:
20+
) -> tuple[list[str], list[str]]:
2121
"""Take line from a constraints or requirements file and process it recursively.
2222
2323
The line is taken as is unless one of the following cases matches:
@@ -69,11 +69,11 @@ def process_line(
6969

7070
def process_io(
7171
fio: typing.IO,
72-
requirements: typing.List[str],
73-
constraints: typing.List[str],
74-
package_keys: typing.List[str],
75-
override_keys: typing.List[str],
76-
ignore_keys: typing.List[str],
72+
requirements: list[str],
73+
constraints: list[str],
74+
package_keys: list[str],
75+
override_keys: list[str],
76+
ignore_keys: list[str],
7777
variety: str,
7878
) -> None:
7979
"""Read lines from an open file and trigger processing of each line
@@ -91,17 +91,17 @@ def process_io(
9191

9292
def resolve_dependencies(
9393
file_or_url: str,
94-
package_keys: typing.List[str],
95-
override_keys: typing.List[str],
96-
ignore_keys: typing.List[str],
94+
package_keys: list[str],
95+
override_keys: list[str],
96+
ignore_keys: list[str],
9797
variety: str = "r",
98-
) -> typing.Tuple[typing.List[str], typing.List[str]]:
98+
) -> tuple[list[str], list[str]]:
9999
"""Takes a file or url, loads it and trigger to recursivly processes its content.
100100
101101
returns tuple of requirements and constraints
102102
"""
103-
requirements: typing.List[str] = []
104-
constraints: typing.List[str] = []
103+
requirements: list[str] = []
104+
constraints: list[str] = []
105105
if not file_or_url.strip():
106106
logger.info("mxdev is configured to run without input requirements!")
107107
return ([], [])
@@ -210,7 +210,7 @@ def fetch(state: State) -> None:
210210
)
211211

212212

213-
def write_dev_sources(fio, packages: typing.Dict[str, typing.Dict[str, typing.Any]]):
213+
def write_dev_sources(fio, packages: dict[str, dict[str, typing.Any]]):
214214
"""Create requirements configuration for fetched source packages."""
215215
if not packages:
216216
return
@@ -232,7 +232,7 @@ def write_dev_sources(fio, packages: typing.Dict[str, typing.Dict[str, typing.An
232232

233233

234234
def write_dev_overrides(
235-
fio, overrides: typing.Dict[str, str], package_keys: typing.List[str]
235+
fio, overrides: dict[str, str], package_keys: list[str]
236236
):
237237
"""Create requirements configuration for overridden packages."""
238238
fio.write("#" * 79 + "\n")
@@ -247,7 +247,7 @@ def write_dev_overrides(
247247
fio.write("\n\n")
248248

249249

250-
def write_main_package(fio, settings: typing.Dict[str, str]):
250+
def write_main_package(fio, settings: dict[str, str]):
251251
"""Write main package if configured."""
252252
main_package = settings.get("main-package")
253253
if main_package:

src/mxdev/state.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
@dataclass
99
class State:
1010
configuration: Configuration
11-
requirements: typing.List[str] = field(default_factory=list)
12-
constraints: typing.List[str] = field(default_factory=list)
11+
requirements: list[str] = field(default_factory=list)
12+
constraints: list[str] = field(default_factory=list)

src/mxdev/vcs/bazaar.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ def bzr_branch(self, **kwargs):
2121
path = self.source["path"]
2222
url = self.source["url"]
2323
if os.path.exists(path):
24-
self.output((logger.info, "Skipped branching existing package %r." % name))
24+
self.output((logger.info, f"Skipped branching existing package {name!r}."))
2525
return
26-
self.output((logger.info, "Branched %r with bazaar." % name))
26+
self.output((logger.info, f"Branched {name!r} with bazaar."))
2727
env = dict(os.environ)
2828
env.pop("PYTHONPATH", None)
2929
cmd = subprocess.Popen(
@@ -42,7 +42,7 @@ def bzr_pull(self, **kwargs):
4242
name = self.source["name"]
4343
path = self.source["path"]
4444
url = self.source["url"]
45-
self.output((logger.info, "Updated %r with bazaar." % name))
45+
self.output((logger.info, f"Updated {name!r} with bazaar."))
4646
env = dict(os.environ)
4747
env.pop("PYTHONPATH", None)
4848
cmd = subprocess.Popen(
@@ -67,12 +67,12 @@ def checkout(self, **kwargs):
6767
self.update(**kwargs)
6868
elif self.matches():
6969
self.output(
70-
(logger.info, "Skipped checkout of existing package %r." % name)
70+
(logger.info, f"Skipped checkout of existing package {name!r}.")
7171
)
7272
else:
7373
raise BazaarError(
74-
"Source URL for existing package %r differs. "
75-
"Expected %r." % (name, self.source["url"])
74+
"Source URL for existing package {!r} differs. "
75+
"Expected {!r}.".format(name, self.source["url"])
7676
)
7777
else:
7878
return self.bzr_branch(**kwargs)
@@ -115,8 +115,8 @@ def update(self, **kwargs):
115115
name = self.source["name"]
116116
if not self.matches():
117117
raise BazaarError(
118-
"Can't update package %r because its URL doesn't match." % name
118+
f"Can't update package {name!r} because its URL doesn't match."
119119
)
120120
if self.status() != "clean" and not kwargs.get("force", False):
121-
raise BazaarError("Can't update package %r because it's dirty." % name)
121+
raise BazaarError(f"Can't update package {name!r} because it's dirty.")
122122
return self.bzr_pull(**kwargs)

0 commit comments

Comments
 (0)