Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit dbf22c5

Browse files
committed
build: add PGH003 and PGH004, add types-colorama
1 parent d968f26 commit dbf22c5

File tree

15 files changed

+45
-35
lines changed

15 files changed

+45
-35
lines changed

commitizen/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import logging.config
33

4-
from colorama import init # type: ignore
4+
from colorama import init
55

66
from commitizen.cz.base import BaseCommitizen
77

commitizen/commands/bump.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,14 @@ def __call__(self) -> None:
331331
"dry_run": dry_run,
332332
}
333333
if self.changelog_to_stdout:
334-
changelog_cmd = Changelog(self.config, {**args, "dry_run": True}) # type: ignore
334+
changelog_cmd = Changelog(self.config, {**args, "dry_run": True}) # type: ignore[typeddict-item]
335335
try:
336336
changelog_cmd()
337337
except DryRunExit:
338338
pass
339339

340340
args["file_name"] = self.file_name
341-
changelog_cmd = Changelog(self.config, args) # type: ignore
341+
changelog_cmd = Changelog(self.config, args) # type: ignore[arg-type]
342342
changelog_cmd()
343343
files.append(changelog_cmd.file_name)
344344

commitizen/commands/changelog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ def _write_changelog(
177177
def _export_template(self) -> None:
178178
tpl = changelog.get_changelog_template(self.cz.template_loader, self.template)
179179
# TODO: fix the following type ignores
180-
src = Path(tpl.filename) # type: ignore
181-
Path(self.export_template_to).write_text(src.read_text()) # type: ignore
180+
src = Path(tpl.filename) # type: ignore[arg-type]
181+
Path(self.export_template_to).write_text(src.read_text()) # type: ignore[arg-type]
182182

183183
def __call__(self) -> None:
184184
commit_parser = self.cz.commit_parser

commitizen/config/base_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def settings(self) -> Settings:
2727

2828
@property
2929
def path(self) -> Path:
30-
return self._path # type: ignore
30+
return self._path # type: ignore[return-value]
3131

3232
@path.setter
3333
def path(self, path: str | Path) -> None:

commitizen/config/toml_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def init_empty_config_content(self) -> None:
3737
with open(self.path, "wb") as output_toml_file:
3838
if parser.get("tool") is None:
3939
parser["tool"] = table()
40-
parser["tool"]["commitizen"] = table() # type: ignore
40+
parser["tool"]["commitizen"] = table() # type: ignore[index]
4141
output_toml_file.write(parser.as_string().encode(self.encoding))
4242

4343
def set_key(self, key: str, value: Any) -> Self:
@@ -49,7 +49,7 @@ def set_key(self, key: str, value: Any) -> Self:
4949
with open(self.path, "rb") as f:
5050
parser = parse(f.read())
5151

52-
parser["tool"]["commitizen"][key] = value # type: ignore
52+
parser["tool"]["commitizen"][key] = value # type: ignore[index]
5353
with open(self.path, "wb") as f:
5454
f.write(parser.as_string().encode(self.encoding))
5555
return self
@@ -68,6 +68,6 @@ def _parse_setting(self, data: bytes | str) -> None:
6868
raise InvalidConfigurationError(f"Failed to parse {self.path}: {e}")
6969

7070
try:
71-
self.settings.update(doc["tool"]["commitizen"]) # type: ignore
71+
self.settings.update(doc["tool"]["commitizen"]) # type: ignore[index,typeddict-item] # TODO: fix this
7272
except exceptions.NonExistentKey:
7373
self.is_empty_config = True

commitizen/cz/customize/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .customize import CustomizeCommitsCz # noqa
1+
from .customize import CustomizeCommitsCz # noqa: F401

commitizen/cz/customize/customize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ def __init__(self, config: BaseConfig) -> None:
4848
setattr(self, attr_name, value)
4949

5050
def questions(self) -> list[CzQuestion]:
51-
return self.custom_settings.get("questions", [{}]) # type: ignore
51+
return self.custom_settings.get("questions", [{}]) # type: ignore[return-value]
5252

5353
def message(self, answers: Mapping[str, Any]) -> str:
5454
message_template = Template(self.custom_settings.get("message_template", ""))
5555
if getattr(Template, "substitute", None):
56-
return message_template.substitute(**answers) # type: ignore
56+
return message_template.substitute(**answers) # type: ignore[attr-defined,no-any-return] # TODO: check if we can fix this
5757
return message_template.render(**answers)
5858

5959
def example(self) -> str:

commitizen/providers/base_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def set_version(self, version: str) -> None:
8686
self.file.write_text(tomlkit.dumps(document))
8787

8888
def get(self, document: tomlkit.TOMLDocument) -> str:
89-
return document["project"]["version"] # type: ignore
89+
return document["project"]["version"] # type: ignore[index,return-value]
9090

9191
def set(self, document: tomlkit.TOMLDocument, version: str) -> None:
92-
document["project"]["version"] = version # type: ignore
92+
document["project"]["version"] = version # type: ignore[index]

commitizen/providers/cargo_provider.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ def lock_file(self) -> Path:
2323

2424
def get(self, document: tomlkit.TOMLDocument) -> str:
2525
try:
26-
return document["package"]["version"] # type: ignore
26+
return document["package"]["version"] # type: ignore[index,return-value]
2727
except tomlkit.exceptions.NonExistentKey:
2828
...
29-
return document["workspace"]["package"]["version"] # type: ignore
29+
return document["workspace"]["package"]["version"] # type: ignore[index,return-value]
3030

3131
def set(self, document: tomlkit.TOMLDocument, version: str) -> None:
3232
try:
33-
document["workspace"]["package"]["version"] = version # type: ignore
33+
document["workspace"]["package"]["version"] = version # type: ignore[index]
3434
return
3535
except tomlkit.exceptions.NonExistentKey:
3636
...
37-
document["package"]["version"] = version # type: ignore
37+
document["package"]["version"] = version # type: ignore[index]
3838

3939
def set_version(self, version: str) -> None:
4040
super().set_version(version)
@@ -44,9 +44,9 @@ def set_version(self, version: str) -> None:
4444
def set_lock_version(self, version: str) -> None:
4545
cargo_toml_content = tomlkit.parse(self.file.read_text())
4646
try:
47-
package_name = cargo_toml_content["package"]["name"] # type: ignore
47+
package_name = cargo_toml_content["package"]["name"] # type: ignore[index]
4848
except tomlkit.exceptions.NonExistentKey:
49-
package_name = cargo_toml_content["workspace"]["package"]["name"] # type: ignore
49+
package_name = cargo_toml_content["workspace"]["package"]["name"] # type: ignore[index]
5050

5151
cargo_lock_content = tomlkit.parse(self.lock_file.read_text())
5252
packages: tomlkit.items.AoT = cargo_lock_content["package"] # type: ignore[assignment]

commitizen/providers/commitizen_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class CommitizenProvider(VersionProvider):
99
"""
1010

1111
def get_version(self) -> str:
12-
return self.config.settings["version"] # type: ignore
12+
return self.config.settings["version"] # type: ignore[return-value] # TODO: check if we can fix this by tweaking the `Settings` type
1313

1414
def set_version(self, version: str) -> None:
1515
self.config.set_key("version", version)

commitizen/providers/poetry_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PoetryProvider(TomlProvider):
1313
filename = "pyproject.toml"
1414

1515
def get(self, pyproject: tomlkit.TOMLDocument) -> str:
16-
return pyproject["tool"]["poetry"]["version"] # type: ignore
16+
return pyproject["tool"]["poetry"]["version"] # type: ignore[index,return-value]
1717

1818
def set(self, pyproject: tomlkit.TOMLDocument, version: str) -> None:
19-
pyproject["tool"]["poetry"]["version"] = version # type: ignore
19+
pyproject["tool"]["poetry"]["version"] = version # type: ignore[index]

commitizen/version_schemes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def bump(
266266

267267
if self.local and is_local_version:
268268
local_version = self.scheme(self.local).bump(increment)
269-
return self.scheme(f"{self.public}+{local_version}") # type: ignore
269+
return self.scheme(f"{self.public}+{local_version}") # type: ignore[return-value]
270270

271271
base = self._get_increment_base(increment, exact_increment)
272272
dev_version = self.generate_devrelease(devrelease)
@@ -283,7 +283,7 @@ def bump(
283283
# TODO: post version
284284
return self.scheme(
285285
f"{base}{pre_version}{dev_version}{self.generate_build_metadata(build_metadata)}"
286-
) # type: ignore
286+
) # type: ignore[return-value]
287287

288288
def _get_increment_base(
289289
self, increment: Increment | None, exact_increment: bool

poetry.lock

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ types-deprecated = "^1.2.9.2"
126126
types-python-dateutil = "^2.8.19.13"
127127
types-PyYAML = ">=5.4.3,<7.0.0"
128128
types-termcolor = "^0.1.1"
129+
types-colorama = "^0.4.15.20240311"
129130

130131
[tool.poetry.group.documentation.dependencies]
131132
mkdocs = "^1.4.2"
@@ -198,6 +199,9 @@ select = [
198199
"UP",
199200
# isort
200201
"I",
202+
# pygrep-hooks
203+
"PGH003",
204+
"PGH004",
201205
# unsorted-dunder-all
202206
"RUF022",
203207
# unused-noqa
@@ -238,16 +242,10 @@ poetry_command = ""
238242

239243
[tool.poe.tasks]
240244
format.help = "Format the code"
241-
format.sequence = [
242-
{ cmd = "ruff check --fix" },
243-
{ cmd = "ruff format" },
244-
]
245+
format.sequence = [{ cmd = "ruff check --fix" }, { cmd = "ruff format" }]
245246

246247
lint.help = "Lint the code"
247-
lint.sequence = [
248-
{ cmd = "ruff check" },
249-
{ cmd = "mypy" },
250-
]
248+
lint.sequence = [{ cmd = "ruff check" }, { cmd = "mypy" }]
251249

252250
check-commit.help = "Check the commit message"
253251
check-commit.cmd = "cz -nr 3 check --rev-range origin/master.."

tests/commands/test_bump_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@ def test_is_initial_tag(mocker: MockFixture, tmp_commitizen_project):
17211721
"extras": None,
17221722
}
17231723

1724-
bump_cmd = bump.Bump(config, arguments) # type: ignore
1724+
bump_cmd = bump.Bump(config, arguments) # type: ignore[arg-type]
17251725

17261726
# Test case 1: No current tag, not yes mode
17271727
mocker.patch("questionary.confirm", return_value=mocker.Mock(ask=lambda: True))

0 commit comments

Comments
 (0)