Skip to content

Restore old branch #1513

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

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e4b048d
refactor: improve readability and fix typos
bearomorphism May 15, 2025
3b4dbbc
refactor(version_scheme): cleanup
bearomorphism May 17, 2025
77b3d4b
refactor(commit): simplify call
bearomorphism May 17, 2025
7a1fb3e
test(commit): when nothing is added to commit
bearomorphism May 17, 2025
b7e6a94
refactor(git): code cleanup and better test coverage
bearomorphism May 15, 2025
262733a
test(git): add test for from_rev_and_commit
bearomorphism May 17, 2025
bb63228
docs(git): from_rev_and_commit docstring
bearomorphism May 17, 2025
8477b89
refactor(EOLType): add eol enum back and reorganize methods
bearomorphism May 18, 2025
5810108
refactor(git): refactor get_tag_names
bearomorphism May 18, 2025
3b163a8
refactor(changelog): minor cleanup
bearomorphism May 19, 2025
5cc58d9
refactor(BaseConfig): use setter
bearomorphism May 20, 2025
06970e6
build(poetry): upgrade mypy version to ^1.15.0
bearomorphism May 20, 2025
d7efb1b
refactor(bump): add type for out, replace function with re escape
bearomorphism May 17, 2025
1b9a177
refactor(bump): clean up
bearomorphism May 16, 2025
2286271
test(bump): improve test coverage
bearomorphism May 16, 2025
360057b
fix(defaults): add non-capitalized default constants back and depreca…
bearomorphism May 22, 2025
1ed9d2d
refactor: misc cleanup
bearomorphism May 17, 2025
37a990b
refactor(git): extract _create_commit_cmd_string
bearomorphism May 19, 2025
5b94792
test(test_git): mock os
bearomorphism May 23, 2025
1d7563e
refactor(cli): early return and improve test coverage
bearomorphism May 23, 2025
978358a
build(termcolor): remove termcolor <3 restriction
bearomorphism May 23, 2025
2ccb269
build: specify importlib-metadata version to fix unit tests
bearomorphism May 25, 2025
baee83e
refactor(changelog): better typing, yield
bearomorphism May 24, 2025
75c90d6
build(deps-dev): bump mypy to 1.16.0
bearomorphism May 23, 2025
3bd7439
refactor(mypy): remove `unused-ignore`
gbaian10 May 31, 2025
d830b2f
refactor(cli.py): add type hints
gbaian10 May 31, 2025
0553197
refactor: add comment clarifying `no_raise` parsing to `list[int]`
gbaian10 May 31, 2025
d7594ae
refactor: remove `TypeError` handling since `Python >=3.9` is required
gbaian10 May 31, 2025
f92f380
fix(deprecated): mark deprecate in v5
bearomorphism Jun 1, 2025
868aa71
build(deps-dev): bump ruff
gbaian10 May 31, 2025
ffccec7
style(ruff): resolve F401
gbaian10 May 31, 2025
ff97584
build(ruff): add RUF022 & RUF100 rules
gbaian10 May 31, 2025
0b2b790
style(ruff): run `ruff check --fix`
gbaian10 May 31, 2025
d799f6b
refactor(BaseCommitizen): remove unused process_commit
bearomorphism May 30, 2025
1269f1c
style(tags): improve types
bearomorphism May 29, 2025
a9aeaf2
perf(tags): use set
bearomorphism May 29, 2025
dd7d41f
refactor: fix mypy output and better type
bearomorphism May 29, 2025
c75d3d0
refactor(conventional_commits): remove unnecessary checks
bearomorphism May 29, 2025
12c0dec
refactor: make methods protected, better type
bearomorphism May 30, 2025
d62821c
style: type untyped methods
bearomorphism May 30, 2025
7d40b04
style: remove Union
bearomorphism May 30, 2025
8287e17
style: better type
bearomorphism May 30, 2025
9b153b4
style: add `-> None` to __init__
bearomorphism May 30, 2025
ee4646d
build(ruff,mypy): more strict rules
bearomorphism May 30, 2025
21fae53
fix(BaseConfig): mypy error
bearomorphism May 31, 2025
afcd5c3
build(mypy): remove disallow_untyped_defs because it's already done b…
bearomorphism May 31, 2025
7ac3ea3
refactor(bump): TypedDict for bump argument
bearomorphism May 30, 2025
b7983ca
refactor(changelog): type untyped arguments
bearomorphism May 31, 2025
b2a7a51
refactor(check): remove unused argument
bearomorphism May 31, 2025
db3c1a0
style(bump): rename class for consistency
bearomorphism May 31, 2025
4aed07c
refactor(check): type CheckArgs arguments
bearomorphism May 31, 2025
5616076
refactor(commit): type commit args
bearomorphism May 31, 2025
735ad12
refactor(commands): remove unused args, type version command args
bearomorphism May 31, 2025
e2702fc
style(cli): shorten arg type
bearomorphism May 31, 2025
e631941
docs(bump): comment on a stupid looking pattern
bearomorphism May 31, 2025
92bbab0
fix(Check): make parameters backward compatiable
bearomorphism May 31, 2025
047779b
style(changelog): rename parameter for consistency
bearomorphism May 31, 2025
945d0c3
refactor(bump): improve readability and still bypass mypy check
bearomorphism May 31, 2025
2fa0452
refactor: remove unnecessary bool() and remove Any type from TypedDic…
bearomorphism May 31, 2025
022e552
style(changelog): add TODO to fixable type ignores
bearomorphism Jun 4, 2025
ba0c043
style(cli): more specific type ignore
bearomorphism Jun 4, 2025
8a3a09b
style(cli): rename kwarg to values
bearomorphism Jun 4, 2025
ff1a5ae
refactor(bump): use any to replace 'or' chain
bearomorphism Jun 6, 2025
e0cc9c4
perf(bump): avoid unnecessary list construction and rename variable t…
bearomorphism Jun 5, 2025
05ec0ba
ci: regenerate poetry lock
bearomorphism Jun 8, 2025
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
Prev Previous commit
Next Next commit
style: type untyped methods
  • Loading branch information
bearomorphism committed Jun 8, 2025
commit d62821cc8a2dcde0fc1aa9cf5c8fb490a37621d5
6 changes: 3 additions & 3 deletions commitizen/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Metadata:
latest_version_position: int | None = None
latest_version_tag: str | None = None

def __post_init__(self):
def __post_init__(self) -> None:
if self.latest_version and not self.latest_version_tag:
# Test syntactic sugar
# latest version tag is optional if same as latest version
Expand Down Expand Up @@ -169,8 +169,8 @@ def process_commit_message(
commit: GitCommit,
changes: dict[str | None, list],
change_type_map: dict[str, str] | None = None,
):
message: dict = {
) -> None:
message: dict[str, Any] = {
"sha1": commit.rev,
"parents": commit.parents,
"author": commit.author,
Expand Down
2 changes: 1 addition & 1 deletion commitizen/commands/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _find_incremental_rev(self, latest_version: str, tags: Iterable[GitTag]) ->

def _write_changelog(
self, changelog_out: str, lines: list[str], changelog_meta: changelog.Metadata
):
) -> None:
with smart_open(self.file_name, "w", encoding=self.encoding) as changelog_file:
partial_changelog: str | None = None
if self.incremental:
Expand Down
4 changes: 2 additions & 2 deletions commitizen/commands/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
class Example:
"""Show an example so people understands the rules."""

def __init__(self, config: BaseConfig, *args):
def __init__(self, config: BaseConfig, *args: object):
self.config: BaseConfig = config
self.cz = factory.committer_factory(self.config)

def __call__(self):
def __call__(self) -> None:
out.write(self.cz.example())
2 changes: 1 addition & 1 deletion commitizen/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def is_pre_commit_installed(self) -> bool:


class Init:
def __init__(self, config: BaseConfig, *args):
def __init__(self, config: BaseConfig, *args: object):
self.config: BaseConfig = config
self.encoding = config.settings["encoding"]
self.cz = factory.committer_factory(self.config)
Expand Down
4 changes: 2 additions & 2 deletions commitizen/commands/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
class Schema:
"""Show structure of the rule."""

def __init__(self, config: BaseConfig, *args):
def __init__(self, config: BaseConfig, *args: object):
self.config: BaseConfig = config
self.cz = factory.committer_factory(self.config)

def __call__(self):
def __call__(self) -> None:
out.write(self.cz.schema())
12 changes: 11 additions & 1 deletion commitizen/config/base_config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING, Any

from commitizen.defaults import DEFAULT_SETTINGS, Settings

if TYPE_CHECKING:
import sys

# Self is Python 3.11+ but backported in typing-extensions
if sys.version_info < (3, 11):
from typing_extensions import Self
else:
from typing import Self


class BaseConfig:
def __init__(self) -> None:
Expand All @@ -28,7 +38,7 @@ def path(self, path: str | Path) -> None:
"""
self._path = Path(path)

def set_key(self, key, value):
def set_key(self, key: str, value: Any) -> Self:
"""Set or update a key in the conf.

For now only strings are supported.
Expand Down
14 changes: 12 additions & 2 deletions commitizen/config/json_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

import json
from pathlib import Path
from typing import TYPE_CHECKING, Any

from commitizen.exceptions import InvalidConfigurationError
from commitizen.git import smart_open

from .base_config import BaseConfig

if TYPE_CHECKING:
import sys

# Self is Python 3.11+ but backported in typing-extensions
if sys.version_info < (3, 11):
from typing_extensions import Self
else:
from typing import Self


class JsonConfig(BaseConfig):
def __init__(self, *, data: bytes | str, path: Path | str):
Expand All @@ -16,11 +26,11 @@ def __init__(self, *, data: bytes | str, path: Path | str):
self.path = path
self._parse_setting(data)

def init_empty_config_content(self):
def init_empty_config_content(self) -> None:
with smart_open(self.path, "a", encoding=self.encoding) as json_file:
json.dump({"commitizen": {}}, json_file)

def set_key(self, key, value):
def set_key(self, key: str, value: Any) -> Self:
"""Set or update a key in the conf.

For now only strings are supported.
Expand Down
18 changes: 14 additions & 4 deletions commitizen/config/toml_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@

import os
from pathlib import Path
from typing import TYPE_CHECKING, Any

from tomlkit import exceptions, parse, table

from commitizen.exceptions import InvalidConfigurationError

from .base_config import BaseConfig

if TYPE_CHECKING:
import sys

# Self is Python 3.11+ but backported in typing-extensions
if sys.version_info < (3, 11):
from typing_extensions import Self
else:
from typing import Self


class TomlConfig(BaseConfig):
def __init__(self, *, data: bytes | str, path: Path | str):
Expand All @@ -17,7 +27,7 @@ def __init__(self, *, data: bytes | str, path: Path | str):
self.path = path
self._parse_setting(data)

def init_empty_config_content(self):
def init_empty_config_content(self) -> None:
if os.path.isfile(self.path):
with open(self.path, "rb") as input_toml_file:
parser = parse(input_toml_file.read())
Expand All @@ -27,10 +37,10 @@ def init_empty_config_content(self):
with open(self.path, "wb") as output_toml_file:
if parser.get("tool") is None:
parser["tool"] = table()
parser["tool"]["commitizen"] = table()
parser["tool"]["commitizen"] = table() # type: ignore
output_toml_file.write(parser.as_string().encode(self.encoding))

def set_key(self, key, value):
def set_key(self, key: str, value: Any) -> Self:
"""Set or update a key in the conf.

For now only strings are supported.
Expand All @@ -39,7 +49,7 @@ def set_key(self, key, value):
with open(self.path, "rb") as f:
parser = parse(f.read())

parser["tool"]["commitizen"][key] = value
parser["tool"]["commitizen"][key] = value # type: ignore
with open(self.path, "wb") as f:
f.write(parser.as_string().encode(self.encoding))
return self
Expand Down
14 changes: 12 additions & 2 deletions commitizen/config/yaml_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING, Any

import yaml

Expand All @@ -9,6 +10,15 @@

from .base_config import BaseConfig

if TYPE_CHECKING:
import sys

# Self is Python 3.11+ but backported in typing-extensions
if sys.version_info < (3, 11):
from typing_extensions import Self
else:
from typing import Self


class YAMLConfig(BaseConfig):
def __init__(self, *, data: bytes | str, path: Path | str):
Expand All @@ -17,7 +27,7 @@ def __init__(self, *, data: bytes | str, path: Path | str):
self.path = path
self._parse_setting(data)

def init_empty_config_content(self):
def init_empty_config_content(self) -> None:
with smart_open(self.path, "a", encoding=self.encoding) as json_file:
yaml.dump({"commitizen": {}}, json_file, explicit_start=True)

Expand All @@ -41,7 +51,7 @@ def _parse_setting(self, data: bytes | str) -> None:
except (KeyError, TypeError):
self.is_empty_config = True

def set_key(self, key, value):
def set_key(self, key: str, value: Any) -> Self:
"""Set or update a key in the conf.

For now only strings are supported.
Expand Down
4 changes: 2 additions & 2 deletions commitizen/cz/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ def message(self, answers: dict) -> str:
"""Format your git message."""

@property
def style(self):
def style(self) -> Style:
return merge_styles(
[
Style(BaseCommitizen.default_style_config),
Style(self.config.settings["style"]),
]
)
) # type: ignore[return-value]

def example(self) -> str:
"""Example of the commit message."""
Expand Down
4 changes: 2 additions & 2 deletions commitizen/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def get_commits(
]


def get_filenames_in_commit(git_reference: str = ""):
def get_filenames_in_commit(git_reference: str = "") -> list[str]:
"""Get the list of files that were committed in the requested git reference.

:param git_reference: a git reference as accepted by `git show`, default: the last commit
Expand Down Expand Up @@ -312,7 +312,7 @@ def get_core_editor() -> str | None:
return None


def smart_open(*args, **kwargs):
def smart_open(*args, **kwargs): # type: ignore[no-untyped-def,unused-ignore]
"""Open a file with the EOL style determined from Git."""
return open(*args, newline=EOLType.for_open(), **kwargs)

Expand Down
5 changes: 3 additions & 2 deletions commitizen/hooks.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import annotations

import os
from collections.abc import Mapping

from commitizen import cmd, out
from commitizen.exceptions import RunHookError


def run(hooks, _env_prefix="CZ_", **env):
def run(hooks: str | list[str], _env_prefix: str = "CZ_", **env: object) -> None:
if isinstance(hooks, str):
hooks = [hooks]

Expand All @@ -24,7 +25,7 @@ def run(hooks, _env_prefix="CZ_", **env):
raise RunHookError(f"Running hook '{hook}' failed")


def _format_env(prefix: str, env: dict[str, str]) -> dict[str, str]:
def _format_env(prefix: str, env: Mapping[str, object]) -> dict[str, str]:
"""_format_env() prefixes all given environment variables with the given
prefix so it can be passed directly to cmd.run()."""
penv = dict(os.environ)
Expand Down
10 changes: 5 additions & 5 deletions commitizen/providers/base_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_version(self) -> str:
"""

@abstractmethod
def set_version(self, version: str):
def set_version(self, version: str) -> None:
"""
Set the new current version
"""
Expand Down Expand Up @@ -58,15 +58,15 @@ def get_version(self) -> str:
document = json.loads(self.file.read_text())
return self.get(document)

def set_version(self, version: str):
def set_version(self, version: str) -> None:
document = json.loads(self.file.read_text())
self.set(document, version)
self.file.write_text(json.dumps(document, indent=self.indent) + "\n")

def get(self, document: dict[str, Any]) -> str:
return document["version"] # type: ignore

def set(self, document: dict[str, Any], version: str):
def set(self, document: dict[str, Any], version: str) -> None:
document["version"] = version


Expand All @@ -79,13 +79,13 @@ def get_version(self) -> str:
document = tomlkit.parse(self.file.read_text())
return self.get(document)

def set_version(self, version: str):
def set_version(self, version: str) -> None:
document = tomlkit.parse(self.file.read_text())
self.set(document, version)
self.file.write_text(tomlkit.dumps(document))

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

def set(self, document: tomlkit.TOMLDocument, version: str):
def set(self, document: tomlkit.TOMLDocument, version: str) -> None:
document["project"]["version"] = version # type: ignore
2 changes: 1 addition & 1 deletion commitizen/providers/cargo_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get(self, document: tomlkit.TOMLDocument) -> str:
...
return document["workspace"]["package"]["version"] # type: ignore

def set(self, document: tomlkit.TOMLDocument, version: str):
def set(self, document: tomlkit.TOMLDocument, version: str) -> None:
try:
document["workspace"]["package"]["version"] = version # type: ignore
return
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 @@ -11,5 +11,5 @@ class CommitizenProvider(VersionProvider):
def get_version(self) -> str:
return self.config.settings["version"] # type: ignore

def set_version(self, version: str):
def set_version(self, version: str) -> None:
self.config.set_key("version", version)
2 changes: 1 addition & 1 deletion commitizen/providers/poetry_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ class PoetryProvider(TomlProvider):
def get(self, pyproject: tomlkit.TOMLDocument) -> str:
return pyproject["tool"]["poetry"]["version"] # type: ignore

def set(self, pyproject: tomlkit.TOMLDocument, version: str):
def set(self, pyproject: tomlkit.TOMLDocument, version: str) -> None:
pyproject["tool"]["poetry"]["version"] = version # type: ignore
2 changes: 1 addition & 1 deletion commitizen/providers/scm_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def get_version(self) -> str:
return "0.0.0"
return str(versions[-1])

def set_version(self, version: str):
def set_version(self, version: str) -> None:
# Not necessary
pass