Skip to content

refactor(bump): TypedDict for bump argument #1475

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
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
18 changes: 11 additions & 7 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from functools import partial
from pathlib import Path
from types import TracebackType
from typing import TYPE_CHECKING, Any, cast
from typing import TYPE_CHECKING, cast

import argcomplete
from decli import cli
Expand Down Expand Up @@ -48,9 +48,9 @@ def __call__(
self,
parser: argparse.ArgumentParser,
namespace: argparse.Namespace,
kwarg: str | Sequence[Any] | None,
kwarg: str | Sequence[object] | None,
option_string: str | None = None,
):
) -> None:
if not isinstance(kwarg, str):
return
if "=" not in kwarg:
Expand Down Expand Up @@ -550,8 +550,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 +585,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 Down Expand Up @@ -621,7 +625,7 @@ class Args(argparse.Namespace):
]


def main():
def main() -> None:
parser: argparse.ArgumentParser = cli(data)
argcomplete.autocomplete(parser)
# Show help if no arg provided
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
Loading