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

build: add PGH003 and PGH004, add types-colorama #1517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion commitizen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import logging.config

from colorama import init # type: ignore
from colorama import init

from commitizen.cz.base import BaseCommitizen

Expand Down
4 changes: 2 additions & 2 deletions commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,14 @@ def __call__(self) -> None:
"dry_run": dry_run,
}
if self.changelog_to_stdout:
changelog_cmd = Changelog(self.config, {**args, "dry_run": True}) # type: ignore
changelog_cmd = Changelog(self.config, {**args, "dry_run": True}) # type: ignore[typeddict-item]
try:
changelog_cmd()
except DryRunExit:
pass

args["file_name"] = self.file_name
changelog_cmd = Changelog(self.config, args) # type: ignore
changelog_cmd = Changelog(self.config, args) # type: ignore[arg-type]
changelog_cmd()
files.append(changelog_cmd.file_name)

Expand Down
4 changes: 2 additions & 2 deletions commitizen/commands/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ def _write_changelog(
def _export_template(self) -> None:
tpl = changelog.get_changelog_template(self.cz.template_loader, self.template)
# TODO: fix the following type ignores
src = Path(tpl.filename) # type: ignore
Path(self.export_template_to).write_text(src.read_text()) # type: ignore
src = Path(tpl.filename) # type: ignore[arg-type]
Path(self.export_template_to).write_text(src.read_text()) # type: ignore[arg-type]

def __call__(self) -> None:
commit_parser = self.cz.commit_parser
Expand Down
2 changes: 1 addition & 1 deletion commitizen/config/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def settings(self) -> Settings:

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

@path.setter
def path(self, path: str | Path) -> None:
Expand Down
6 changes: 3 additions & 3 deletions commitizen/config/toml_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def init_empty_config_content(self) -> None:
with open(self.path, "wb") as output_toml_file:
if parser.get("tool") is None:
parser["tool"] = table()
parser["tool"]["commitizen"] = table() # type: ignore
parser["tool"]["commitizen"] = table() # type: ignore[index]
output_toml_file.write(parser.as_string().encode(self.encoding))

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

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

try:
self.settings.update(doc["tool"]["commitizen"]) # type: ignore
self.settings.update(doc["tool"]["commitizen"]) # type: ignore[index,typeddict-item] # TODO: fix this
except exceptions.NonExistentKey:
self.is_empty_config = True
2 changes: 1 addition & 1 deletion commitizen/cz/customize/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .customize import CustomizeCommitsCz # noqa
from .customize import CustomizeCommitsCz # noqa: F401
4 changes: 2 additions & 2 deletions commitizen/cz/customize/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ def __init__(self, config: BaseConfig) -> None:
setattr(self, attr_name, value)

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

def message(self, answers: Mapping[str, Any]) -> str:
message_template = Template(self.custom_settings.get("message_template", ""))
if getattr(Template, "substitute", None):
return message_template.substitute(**answers) # type: ignore
return message_template.substitute(**answers) # type: ignore[attr-defined,no-any-return] # pragma: no cover # TODO: check if we can fix this
Comment on lines 55 to +56
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related PR: #74

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might need to check the standard string lib 🤔

return message_template.render(**answers)

def example(self) -> str:
Expand Down
4 changes: 2 additions & 2 deletions commitizen/providers/base_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def set_version(self, version: str) -> None:
self.file.write_text(tomlkit.dumps(document))

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

def set(self, document: tomlkit.TOMLDocument, version: str) -> None:
document["project"]["version"] = version # type: ignore
document["project"]["version"] = version # type: ignore[index]
12 changes: 6 additions & 6 deletions commitizen/providers/cargo_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ def lock_file(self) -> Path:

def get(self, document: tomlkit.TOMLDocument) -> str:
try:
return document["package"]["version"] # type: ignore
return document["package"]["version"] # type: ignore[index,return-value]
except tomlkit.exceptions.NonExistentKey:
...
return document["workspace"]["package"]["version"] # type: ignore
return document["workspace"]["package"]["version"] # type: ignore[index,return-value]

def set(self, document: tomlkit.TOMLDocument, version: str) -> None:
try:
document["workspace"]["package"]["version"] = version # type: ignore
document["workspace"]["package"]["version"] = version # type: ignore[index]
return
except tomlkit.exceptions.NonExistentKey:
...
document["package"]["version"] = version # type: ignore
document["package"]["version"] = version # type: ignore[index]

def set_version(self, version: str) -> None:
super().set_version(version)
Expand All @@ -44,9 +44,9 @@ def set_version(self, version: str) -> None:
def set_lock_version(self, version: str) -> None:
cargo_toml_content = tomlkit.parse(self.file.read_text())
try:
package_name = cargo_toml_content["package"]["name"] # type: ignore
package_name = cargo_toml_content["package"]["name"] # type: ignore[index]
except tomlkit.exceptions.NonExistentKey:
package_name = cargo_toml_content["workspace"]["package"]["name"] # type: ignore
package_name = cargo_toml_content["workspace"]["package"]["name"] # type: ignore[index]

cargo_lock_content = tomlkit.parse(self.lock_file.read_text())
packages: tomlkit.items.AoT = cargo_lock_content["package"] # type: ignore[assignment]
Expand Down
2 changes: 1 addition & 1 deletion commitizen/providers/commitizen_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CommitizenProvider(VersionProvider):
"""

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

def set_version(self, version: str) -> None:
self.config.set_key("version", version)
4 changes: 2 additions & 2 deletions commitizen/providers/poetry_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PoetryProvider(TomlProvider):
filename = "pyproject.toml"

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

def set(self, pyproject: tomlkit.TOMLDocument, version: str) -> None:
pyproject["tool"]["poetry"]["version"] = version # type: ignore
pyproject["tool"]["poetry"]["version"] = version # type: ignore[index]
4 changes: 2 additions & 2 deletions commitizen/version_schemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def bump(

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

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

def _get_increment_base(
self, increment: Increment | None, exact_increment: bool
Expand Down
14 changes: 13 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ types-deprecated = "^1.2.9.2"
types-python-dateutil = "^2.8.19.13"
types-PyYAML = ">=5.4.3,<7.0.0"
types-termcolor = "^0.1.1"
types-colorama = "^0.4.15.20240311"

[tool.poetry.group.documentation.dependencies]
mkdocs = "^1.4.2"
Expand Down Expand Up @@ -198,6 +199,9 @@ select = [
"UP",
# isort
"I",
# pygrep-hooks
"PGH003",
"PGH004",
# unsorted-dunder-all
"RUF022",
# unused-noqa
Expand Down Expand Up @@ -238,16 +242,10 @@ poetry_command = ""

[tool.poe.tasks]
format.help = "Format the code"
format.sequence = [
{ cmd = "ruff check --fix" },
{ cmd = "ruff format" },
]
format.sequence = [{ cmd = "ruff check --fix" }, { cmd = "ruff format" }]

lint.help = "Lint the code"
lint.sequence = [
{ cmd = "ruff check" },
{ cmd = "mypy" },
]
lint.sequence = [{ cmd = "ruff check" }, { cmd = "mypy" }]

check-commit.help = "Check the commit message"
check-commit.cmd = "cz -nr 3 check --rev-range origin/master.."
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ def test_is_initial_tag(mocker: MockFixture, tmp_commitizen_project):
"extras": None,
}

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

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