Skip to content

Commit a48d263

Browse files
noirbizarreLee-W
authored andcommitted
style(ruff): enable pyupgrade (UP) rules and fix them all
1 parent 12b214e commit a48d263

23 files changed

+76
-88
lines changed

‎commitizen/bump.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _bump_with_regex(
9797
current_version_found = False
9898
lines = []
9999
pattern = re.compile(regex)
100-
with open(version_filepath, "r", encoding=encoding) as f:
100+
with open(version_filepath, encoding=encoding) as f:
101101
for line in f:
102102
if pattern.search(line):
103103
bumped_line = line.replace(current_version, new_version)

‎commitizen/changelog.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import re
3131
from collections import OrderedDict, defaultdict
3232
from datetime import date
33-
from typing import TYPE_CHECKING, Callable, Iterable, Type, cast
33+
from typing import TYPE_CHECKING, Callable, Iterable, cast
3434

3535
from jinja2 import Environment, PackageLoader
3636

@@ -74,7 +74,7 @@ def tag_included_in_changelog(
7474
return True
7575

7676

77-
def get_version_tags(scheme: Type[BaseVersion], tags: list[GitTag]) -> list[GitTag]:
77+
def get_version_tags(scheme: type[BaseVersion], tags: list[GitTag]) -> list[GitTag]:
7878
valid_tags: list[GitTag] = []
7979
for tag in tags:
8080
try:
@@ -230,7 +230,7 @@ def get_metadata(
230230
"latest_version_position": None,
231231
}
232232

233-
with open(filepath, "r", encoding=encoding) as changelog_file:
233+
with open(filepath, encoding=encoding) as changelog_file:
234234
for index, line in enumerate(changelog_file):
235235
line = line.strip().lower()
236236

‎commitizen/changelog_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def find_version_blocks(filepath: str, encoding: str = encoding) -> Generator:
5555
5656
```
5757
"""
58-
with open(filepath, "r", encoding=encoding) as f:
58+
with open(filepath, encoding=encoding) as f:
5959
block: list = []
6060
for line in f:
6161
line = line.strip("\n")

‎commitizen/commands/bump.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,9 @@ def is_initial_tag(self, current_tag_version: str, is_yes: bool = False) -> bool
8787
else:
8888
out.info(f"Tag {current_tag_version} could not be found. ")
8989
out.info(
90-
(
91-
"Possible causes:\n"
92-
"- version in configuration is not the current version\n"
93-
"- tag_format is missing, check them using 'git tag --list'\n"
94-
)
90+
"Possible causes:\n"
91+
"- version in configuration is not the current version\n"
92+
"- tag_format is missing, check them using 'git tag --list'\n"
9593
)
9694
is_initial = questionary.confirm("Is this the first tag created?").ask()
9795
return is_initial

‎commitizen/commands/changelog.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def __call__(self):
192192

193193
lines = []
194194
if self.incremental and os.path.isfile(self.file_name):
195-
with open(self.file_name, "r", encoding=self.encoding) as changelog_file:
195+
with open(self.file_name, encoding=self.encoding) as changelog_file:
196196
lines = changelog_file.readlines()
197197

198198
self.write_changelog(changelog_out, lines, changelog_meta)

‎commitizen/commands/check.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import re
55
import sys
6-
from typing import Any, List
6+
from typing import Any
77

88
from commitizen import factory, git, out
99
from commitizen.config import BaseConfig
@@ -35,7 +35,7 @@ def __init__(self, config: BaseConfig, arguments: dict[str, Any], cwd=os.getcwd(
3535
# we need to distinguish between None and [], which is a valid value
3636

3737
allowed_prefixes = arguments.get("allowed_prefixes")
38-
self.allowed_prefixes: List[str] = (
38+
self.allowed_prefixes: list[str] = (
3939
allowed_prefixes
4040
if allowed_prefixes is not None
4141
else config.settings["allowed_prefixes"]
@@ -56,10 +56,8 @@ def _valid_command_argument(self):
5656
self.commit_msg: str | None = sys.stdin.read()
5757
elif num_exclusive_args_provided != 1:
5858
raise InvalidCommandArgumentError(
59-
(
60-
"Only one of --rev-range, --message, and --commit-msg-file is permitted by check command! "
61-
"See 'cz check -h' for more information"
62-
)
59+
"Only one of --rev-range, --message, and --commit-msg-file is permitted by check command! "
60+
"See 'cz check -h' for more information"
6361
)
6462

6563
def __call__(self):
@@ -98,7 +96,7 @@ def _get_commits(self):
9896
# Get commit message from file (--commit-msg-file)
9997
if self.commit_msg_file is not None:
10098
# Enter this branch if commit_msg_file is "".
101-
with open(self.commit_msg_file, "r", encoding=self.encoding) as commit_file:
99+
with open(self.commit_msg_file, encoding=self.encoding) as commit_file:
102100
msg = commit_file.read()
103101
# Get commit message from command line (--message)
104102
elif self.commit_msg is not None:

‎commitizen/commands/commit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def read_backup_message(self) -> str:
4242
raise NoCommitBackupError()
4343

4444
# Read commit message from backup
45-
with open(self.temp_file, "r", encoding=self.encoding) as f:
45+
with open(self.temp_file, encoding=self.encoding) as f:
4646
return f.read().strip()
4747

4848
def prompt_commit_questions(self) -> str:

‎commitizen/config/json_config.py

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

1212
class JsonConfig(BaseConfig):
1313
def __init__(self, *, data: bytes | str, path: Path | str):
14-
super(JsonConfig, self).__init__()
14+
super().__init__()
1515
self.is_empty_config = False
1616
self.add_path(path)
1717
self._parse_setting(data)

‎commitizen/config/toml_config.py

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

1212
class TomlConfig(BaseConfig):
1313
def __init__(self, *, data: bytes | str, path: Path | str):
14-
super(TomlConfig, self).__init__()
14+
super().__init__()
1515
self.is_empty_config = False
1616
self.add_path(path)
1717
self._parse_setting(data)

‎commitizen/config/yaml_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class YAMLConfig(BaseConfig):
1414
def __init__(self, *, data: bytes | str, path: Path | str):
15-
super(YAMLConfig, self).__init__()
15+
super().__init__()
1616
self.is_empty_config = False
1717
self.add_path(path)
1818
self._parse_setting(data)

‎commitizen/cz/conventional_commits/conventional_commits.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def schema_pattern(self) -> str:
202202
def info(self) -> str:
203203
dir_path = os.path.dirname(os.path.realpath(__file__))
204204
filepath = os.path.join(dir_path, "conventional_commits_info.txt")
205-
with open(filepath, "r", encoding=self.config.settings["encoding"]) as f:
205+
with open(filepath, encoding=self.config.settings["encoding"]) as f:
206206
content = f.read()
207207
return content
208208

‎commitizen/cz/customize/customize.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CustomizeCommitsCz(BaseCommitizen):
2222
change_type_order = defaults.change_type_order
2323

2424
def __init__(self, config: BaseConfig):
25-
super(CustomizeCommitsCz, self).__init__(config)
25+
super().__init__(config)
2626

2727
if "customize" not in self.config.settings:
2828
raise MissingCzCustomizeConfigError()
@@ -81,7 +81,7 @@ def info(self) -> str | None:
8181
info_path = self.custom_settings.get("info_path")
8282
info = self.custom_settings.get("info")
8383
if info_path:
84-
with open(info_path, "r", encoding=self.config.settings["encoding"]) as f:
84+
with open(info_path, encoding=self.config.settings["encoding"]) as f:
8585
content = f.read()
8686
return content
8787
elif info:

‎commitizen/cz/jira/jira.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ def schema_pattern(self) -> str:
7676
def info(self) -> str:
7777
dir_path = os.path.dirname(os.path.realpath(__file__))
7878
filepath = os.path.join(dir_path, "jira_info.txt")
79-
with open(filepath, "r", encoding=self.config.settings["encoding"]) as f:
79+
with open(filepath, encoding=self.config.settings["encoding"]) as f:
8080
content = f.read()
8181
return content

‎commitizen/defaults.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
from __future__ import annotations
22

33
import pathlib
4-
import sys
54
from collections import OrderedDict
65
from typing import Any, Iterable, MutableMapping
76

8-
if sys.version_info < (3, 8):
9-
from typing_extensions import TypedDict
10-
else:
11-
from typing import TypedDict
7+
from typing import TypedDict
128

139
# Type
1410
Questions = Iterable[MutableMapping[str, Any]]

‎commitizen/version_schemes.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import warnings
66
from itertools import zip_longest
7-
from typing import TYPE_CHECKING, ClassVar, Type, cast
7+
from typing import TYPE_CHECKING, ClassVar, Protocol, Type, cast, runtime_checkable
88

99
import importlib_metadata as metadata
1010
from packaging.version import InvalidVersion # noqa: F401: Rexpose the common exception
@@ -14,11 +14,6 @@
1414
from commitizen.defaults import MAJOR, MINOR, PATCH
1515
from commitizen.exceptions import VersionSchemeUnknown
1616

17-
if sys.version_info >= (3, 8):
18-
from typing import Protocol, runtime_checkable
19-
else:
20-
from typing_extensions import Protocol, runtime_checkable
21-
2217
if TYPE_CHECKING:
2318
# TypeAlias is Python 3.10+ but backported in typing-extensions
2419
if sys.version_info >= (3, 10):

‎pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ addopts = "--strict-markers"
133133

134134
[tool.ruff]
135135
line-length = 88
136+
select = ["E", "F", "UP"]
136137
ignore = [
137138
"E501",
138139
"D1",

‎tests/commands/test_bump_command.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,10 @@ def test_bump_files_only(mocker: MockFixture, tmp_commitizen_project):
406406
tag_exists = git.tag_exist("0.3.0")
407407
assert tag_exists is False
408408

409-
with open(tmp_version_file, "r", encoding="utf-8") as f:
409+
with open(tmp_version_file, encoding="utf-8") as f:
410410
assert "0.3.0" in f.read()
411411

412-
with open(tmp_commitizen_cfg_file, "r", encoding="utf-8") as f:
412+
with open(tmp_commitizen_cfg_file, encoding="utf-8") as f:
413413
assert "0.3.0" in f.read()
414414

415415

@@ -431,7 +431,7 @@ def test_bump_local_version(mocker: MockFixture, tmp_commitizen_project):
431431
tag_exists = git.tag_exist("4.5.1+0.2.0")
432432
assert tag_exists is True
433433

434-
with open(tmp_version_file, "r", encoding="utf-8") as f:
434+
with open(tmp_version_file, encoding="utf-8") as f:
435435
assert "4.5.1+0.2.0" in f.read()
436436

437437

@@ -511,7 +511,7 @@ def test_bump_with_changelog_arg(mocker: MockFixture, changelog_path):
511511
tag_exists = git.tag_exist("0.2.0")
512512
assert tag_exists is True
513513

514-
with open(changelog_path, "r", encoding="utf-8") as f:
514+
with open(changelog_path, encoding="utf-8") as f:
515515
out = f.read()
516516
assert out.startswith("#")
517517
assert "0.2.0" in out
@@ -529,7 +529,7 @@ def test_bump_with_changelog_config(mocker: MockFixture, changelog_path, config_
529529
tag_exists = git.tag_exist("0.2.0")
530530
assert tag_exists is True
531531

532-
with open(changelog_path, "r", encoding="utf-8") as f:
532+
with open(changelog_path, encoding="utf-8") as f:
533533
out = f.read()
534534
assert out.startswith("#")
535535
assert "0.2.0" in out
@@ -572,7 +572,7 @@ def test_bump_with_changelog_to_stdout_arg(mocker: MockFixture, capsys, changelo
572572
tag_exists = git.tag_exist("0.2.0")
573573
assert tag_exists is True
574574

575-
with open(changelog_path, "r", encoding="utf-8") as f:
575+
with open(changelog_path, encoding="utf-8") as f:
576576
out = f.read()
577577
assert out.startswith("#")
578578
assert "0.2.0" in out
@@ -911,7 +911,7 @@ def test_bump_command_prelease_scheme_via_cli(
911911
assert tag_exists is True
912912

913913
for version_file in [tmp_version_file, tmp_commitizen_cfg_file]:
914-
with open(version_file, "r") as f:
914+
with open(version_file) as f:
915915
assert "0.2.0-a0" in f.read()
916916

917917
# PRERELEASE BUMP CREATES VERSION WITHOUT PRERELEASE
@@ -923,7 +923,7 @@ def test_bump_command_prelease_scheme_via_cli(
923923
assert tag_exists is True
924924

925925
for version_file in [tmp_version_file, tmp_commitizen_cfg_file]:
926-
with open(version_file, "r") as f:
926+
with open(version_file) as f:
927927
assert "0.2.0" in f.read()
928928

929929

@@ -944,7 +944,7 @@ def test_bump_command_prelease_scheme_via_config(
944944
assert tag_exists is True
945945

946946
for version_file in [tmp_version_file, tmp_commitizen_cfg_file]:
947-
with open(version_file, "r") as f:
947+
with open(version_file) as f:
948948
assert "0.2.0-a0" in f.read()
949949

950950
testargs = ["cz", "bump", "--prerelease", "alpha", "--yes"]
@@ -955,7 +955,7 @@ def test_bump_command_prelease_scheme_via_config(
955955
assert tag_exists is True
956956

957957
for version_file in [tmp_version_file, tmp_commitizen_cfg_file]:
958-
with open(version_file, "r") as f:
958+
with open(version_file) as f:
959959
assert "0.2.0-a1" in f.read()
960960

961961
# PRERELEASE BUMP CREATES VERSION WITHOUT PRERELEASE
@@ -967,7 +967,7 @@ def test_bump_command_prelease_scheme_via_config(
967967
assert tag_exists is True
968968

969969
for version_file in [tmp_version_file, tmp_commitizen_cfg_file]:
970-
with open(version_file, "r") as f:
970+
with open(version_file) as f:
971971
assert "0.2.0" in f.read()
972972

973973

@@ -988,7 +988,7 @@ def test_bump_command_prelease_scheme_check_old_tags(
988988
assert tag_exists is True
989989

990990
for version_file in [tmp_version_file, tmp_commitizen_cfg_file]:
991-
with open(version_file, "r") as f:
991+
with open(version_file) as f:
992992
assert "0.2.0-a0" in f.read()
993993

994994
testargs = ["cz", "bump", "--prerelease", "alpha"]
@@ -999,7 +999,7 @@ def test_bump_command_prelease_scheme_check_old_tags(
999999
assert tag_exists is True
10001000

10011001
for version_file in [tmp_version_file, tmp_commitizen_cfg_file]:
1002-
with open(version_file, "r") as f:
1002+
with open(version_file) as f:
10031003
assert "0.2.0-a1" in f.read()
10041004

10051005
# PRERELEASE BUMP CREATES VERSION WITHOUT PRERELEASE
@@ -1011,7 +1011,7 @@ def test_bump_command_prelease_scheme_check_old_tags(
10111011
assert tag_exists is True
10121012

10131013
for version_file in [tmp_version_file, tmp_commitizen_cfg_file]:
1014-
with open(version_file, "r") as f:
1014+
with open(version_file) as f:
10151015
assert "0.2.0" in f.read()
10161016

10171017

0 commit comments

Comments
 (0)