Skip to content

Redo #1466, #1479 and #1480 #1511

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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ec97453
ci(mypy): fix linter error
bearomorphism Jun 8, 2025
304c98c
style(tags): improve types
bearomorphism May 29, 2025
ebaa152
perf(tags): use set
bearomorphism May 29, 2025
76cc333
refactor: fix mypy output and better type
bearomorphism May 29, 2025
21eb968
refactor(conventional_commits): remove unnecessary checks
bearomorphism May 29, 2025
652fd82
refactor: make methods protected, better type
bearomorphism May 30, 2025
afcf662
style: remove unnecessary noqa
bearomorphism May 30, 2025
8c0ff1b
style: type untyped methods
bearomorphism May 30, 2025
eee01b0
style: remove Union
bearomorphism May 30, 2025
d60167b
style: better type
bearomorphism May 30, 2025
6350ff0
style: add `-> None` to __init__
bearomorphism May 30, 2025
4a69986
build(ruff,mypy): more strict rules
bearomorphism May 30, 2025
93c5b66
fix(BaseConfig): mypy error
bearomorphism May 31, 2025
f9df10c
build(mypy): remove disallow_untyped_defs because it's already done b…
bearomorphism May 31, 2025
b773bdc
refactor(bump): TypedDict for bump argument
bearomorphism May 30, 2025
b7af25b
refactor(changelog): type untyped arguments
bearomorphism May 31, 2025
9c5c4b8
refactor(check): remove unused argument
bearomorphism May 31, 2025
bb022ad
style(bump): rename class for consistency
bearomorphism May 31, 2025
a6f4e9f
refactor(check): type CheckArgs arguments
bearomorphism May 31, 2025
f45511f
refactor(commit): type commit args
bearomorphism May 31, 2025
bf4f055
refactor(commands): remove unused args, type version command args
bearomorphism May 31, 2025
612d0b7
style(cli): shorten arg type
bearomorphism May 31, 2025
d5f9bfd
docs(bump): comment on a stupid looking pattern
bearomorphism May 31, 2025
d1efd89
fix(Check): make parameters backward compatiable
bearomorphism May 31, 2025
8ab16a4
style(changelog): rename parameter for consistency
bearomorphism May 31, 2025
bd7b80f
refactor(bump): improve readability and still bypass mypy check
bearomorphism May 31, 2025
a35196d
refactor: remove unnecessary bool() and remove Any type from TypedDic…
bearomorphism May 31, 2025
d63285e
style(changelog): add TODO to fixable type ignores
bearomorphism Jun 4, 2025
e467463
style(cli): more specific type ignore
bearomorphism Jun 4, 2025
d2e1821
style(cli): rename kwarg to values
bearomorphism Jun 4, 2025
31194f7
refactor(bump): use any to replace 'or' chain
bearomorphism Jun 6, 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
16 changes: 8 additions & 8 deletions commitizen/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import re
from collections import OrderedDict, defaultdict
from collections.abc import Generator, Iterable, Mapping
from collections.abc import Generator, Iterable, Mapping, Sequence
from dataclasses import dataclass
from datetime import date
from typing import TYPE_CHECKING, Any
Expand Down 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 Expand Up @@ -225,7 +225,7 @@ def render_changelog(
tree: Iterable,
loader: BaseLoader,
template: str,
**kwargs,
**kwargs: Any,
) -> str:
jinja_template = get_changelog_template(loader, template)
changelog: str = jinja_template.render(tree=tree, **kwargs)
Expand Down Expand Up @@ -282,7 +282,7 @@ def incremental_build(


def get_smart_tag_range(
tags: list[GitTag], newest: str, oldest: str | None = None
tags: Sequence[GitTag], newest: str, oldest: str | None = None
) -> list[GitTag]:
"""Smart because it finds the N+1 tag.

Expand All @@ -308,10 +308,10 @@ def get_smart_tag_range(


def get_oldest_and_newest_rev(
tags: list[GitTag],
tags: Sequence[GitTag],
version: str,
rules: TagRules,
) -> tuple[str | None, str | None]:
) -> tuple[str | None, str]:
"""Find the tags for the given version.

`version` may come in different formats:
Expand Down
2 changes: 1 addition & 1 deletion commitizen/changelog_formats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ChangelogFormat(Protocol):

config: BaseConfig

def __init__(self, config: BaseConfig):
def __init__(self, config: BaseConfig) -> None:
self.config = config

@property
Expand Down
2 changes: 1 addition & 1 deletion commitizen/changelog_formats/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BaseFormat(ChangelogFormat, metaclass=ABCMeta):
extension: ClassVar[str] = ""
alternative_extensions: ClassVar[set[str]] = set()

def __init__(self, config: BaseConfig):
def __init__(self, config: BaseConfig) -> None:
# Constructor needs to be redefined because `Protocol` prevent instantiation by default
# See: https://bugs.python.org/issue44807
self.config = config
Expand Down
52 changes: 40 additions & 12 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import argparse
import logging
import sys
from collections.abc import Sequence
from copy import deepcopy
from functools import partial
from pathlib import Path
from types import TracebackType
from typing import Any
from typing import TYPE_CHECKING

import argcomplete
from decli import cli
Expand Down Expand Up @@ -48,17 +47,17 @@ def __call__(
self,
parser: argparse.ArgumentParser,
namespace: argparse.Namespace,
kwarg: str | Sequence[Any] | None,
values: object,
option_string: str | None = None,
):
if not isinstance(kwarg, str):
) -> None:
if not isinstance(values, str):
return
if "=" not in kwarg:
if "=" not in values:
raise InvalidCommandArgumentError(
f"Option {option_string} expect a key=value format"
)
kwargs = getattr(namespace, self.dest, None) or {}
key, value = kwarg.split("=", 1)
key, value = values.split("=", 1)
if not key:
raise InvalidCommandArgumentError(
f"Option {option_string} expect a key=value format"
Expand Down Expand Up @@ -550,8 +549,12 @@ def __call__(


def commitizen_excepthook(
type, value, traceback, debug=False, no_raise: list[int] | None = None
):
type: type[BaseException],
value: BaseException,
traceback: TracebackType | None,
debug: bool = False,
no_raise: list[int] | None = None,
) -> None:
traceback = traceback if isinstance(traceback, TracebackType) else None
if not isinstance(value, CommitizenException):
original_excepthook(type, value, traceback)
Expand Down Expand Up @@ -581,7 +584,7 @@ def parse_no_raise(comma_separated_no_raise: str) -> list[int]:
represents the exit code found in exceptions.
"""
no_raise_items: list[str] = comma_separated_no_raise.split(",")
no_raise_codes = []
no_raise_codes: list[int] = []
for item in no_raise_items:
if item.isdecimal():
no_raise_codes.append(int(item))
Expand All @@ -596,8 +599,33 @@ def parse_no_raise(comma_separated_no_raise: str) -> list[int]:
return no_raise_codes


def main():
parser = cli(data)
if TYPE_CHECKING:

class Args(argparse.Namespace):
config: str | None = None
debug: bool = False
name: str | None = None
no_raise: str | None = None # comma-separated string, later parsed as list[int]
report: bool = False
project: bool = False
commitizen: bool = False
verbose: bool = False
func: type[
commands.Init # init
| commands.Commit # commit (c)
| commands.ListCz # ls
| commands.Example # example
| commands.Info # info
| commands.Schema # schema
| commands.Bump # bump
| commands.Changelog # changelog (ch)
| commands.Check # check
| commands.Version # version
]


def main() -> None:
parser: argparse.ArgumentParser = cli(data)
argcomplete.autocomplete(parser)
# Show help if no arg provided
if len(sys.argv) == 1:
Expand Down
5 changes: 4 additions & 1 deletion commitizen/cmd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import annotations

import os
import subprocess
from collections.abc import Mapping
from typing import NamedTuple

from charset_normalizer import from_bytes
Expand Down Expand Up @@ -28,7 +31,7 @@ def _try_decode(bytes_: bytes) -> str:
raise CharacterSetDecodeError() from e


def run(cmd: str, env=None) -> Command:
def run(cmd: str, env: Mapping[str, str] | None = None) -> Command:
if env is not None:
env = {**os.environ, **env}
process = subprocess.Popen(
Expand Down
Loading