Skip to content

Commit

Permalink
refactor(#132): remove @beartype decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKing committed Jul 5, 2024
1 parent 5cf581f commit 97e09c8
Show file tree
Hide file tree
Showing 22 changed files with 2 additions and 83 deletions.
3 changes: 0 additions & 3 deletions calcipy/can_skip.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

from pathlib import Path

from beartype import beartype
from beartype.typing import List
from corallium.log import LOGGER


@beartype
def can_skip(*, prerequisites: List[Path], targets: List[Path]) -> bool:
"""Return true if the prerequisite files are have newer `mtime` than targets.
Expand All @@ -33,7 +31,6 @@ def test(ctx: Context) -> None:
return False


@beartype
def dont_skip(*, prerequisites: List[Path], targets: List[Path]) -> bool:
"""To use for testing with mock; always returns False."""
LOGGER.debug('Mocking can_skip', prerequisites=prerequisites, targets=targets)
Expand Down
9 changes: 0 additions & 9 deletions calcipy/check_for_stale_packages/_check_for_stale_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import arrow
import httpx
from arrow import Arrow
from beartype import beartype
from beartype.typing import Awaitable, Callable, Dict, List, Optional, Tuple, TypeVar, Union
from corallium.file_helpers import LOCK
from corallium.log import LOGGER
Expand Down Expand Up @@ -84,7 +83,6 @@ async def _get_release_date(package: _HostedPythonPackage) -> _HostedPythonPacka
return package


@beartype
def _read_cache(path_pack_lock: Path = CALCIPY_CACHE) -> Dict[str, _HostedPythonPackage]:
"""Read the cached packaging information.
Expand Down Expand Up @@ -157,7 +155,6 @@ async def task(idx: int, op: Callable[[], Awaitable[_OpReturnT]]) -> Tuple[_OpRe
return results


@beartype
async def _collect_release_dates(
packages: List[_HostedPythonPackage],
old_cache: Optional[Dict[str, _HostedPythonPackage]] = None,
Expand Down Expand Up @@ -207,7 +204,6 @@ async def fetch(package: _HostedPythonPackage) -> _HostedPythonPackage | None:
return updated_packages


@beartype
def _write_cache(updated_packages: List[_HostedPythonPackage], path_pack_lock: Path = CALCIPY_CACHE) -> None:
"""Read the cached packaging information.
Expand All @@ -221,7 +217,6 @@ def _write_cache(updated_packages: List[_HostedPythonPackage], path_pack_lock: P
path_pack_lock.write_text(pretty_json + '\n', encoding='utf-8')


@beartype
def _read_packages(path_lock: Path) -> List[_HostedPythonPackage]:
"""Read packages from lock file. Currently only support `poetry.lock`, but could support more in the future.
Expand Down Expand Up @@ -249,7 +244,6 @@ def _read_packages(path_lock: Path) -> List[_HostedPythonPackage]:
]


@beartype
def _packages_are_stale(packages: List[_HostedPythonPackage], *, stale_months: int) -> bool:
"""Check for stale packages. Raise error and log all stale versions found.
Expand All @@ -258,8 +252,6 @@ def _packages_are_stale(packages: List[_HostedPythonPackage], *, stale_months: i
stale_months: cutoff in months for when a package might be stale enough to be a risk
"""

@beartype
def format_package(pack: _HostedPythonPackage) -> str:
delta = pack.datetime.humanize() # type: ignore[union-attr]
latest = '' if pack.version == pack.latest_version else f' (*New version available: {pack.latest_version}*)'
Expand All @@ -277,7 +269,6 @@ def format_package(pack: _HostedPythonPackage) -> str:
return bool(stale_packages)


@beartype
def check_for_stale_packages(*, stale_months: int, path_lock: Path = LOCK, path_cache: Path = CALCIPY_CACHE) -> bool:
"""Check for stale packages by reading from the cache, and updating if necessary.
Expand Down
2 changes: 0 additions & 2 deletions calcipy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pathlib import Path
from types import ModuleType

from beartype import beartype
from beartype.typing import Any, Callable, Dict, List, Optional, Union
from invoke.collection import Collection as InvokeCollection # noqa: TID251
from invoke.config import Config, merge_dicts
Expand Down Expand Up @@ -56,7 +55,6 @@ def global_defaults() -> Dict: # type: ignore[type-arg] # pragma: no cover
return merge_dicts(invoke_defaults, calcipy_defaults)


@beartype
def start_program(
pkg_name: str,
pkg_version: str,
Expand Down
9 changes: 0 additions & 9 deletions calcipy/code_tag_collector/_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from subprocess import CalledProcessError # nosec # noqa: S404

import arrow
from beartype import beartype
from beartype.typing import Dict, List, Pattern, Sequence, Tuple
from corallium.file_helpers import read_lines
from corallium.log import LOGGER
Expand Down Expand Up @@ -54,7 +53,6 @@ class _Tags(BaseModel):
model_config = ConfigDict(frozen=True)


@beartype
def _search_lines(
lines: List[str],
regex_compiled: Pattern[str],
Expand Down Expand Up @@ -86,7 +84,6 @@ def _search_lines(
return comments


@beartype
def _search_files(paths_source: Sequence[Path], regex_compiled: Pattern[str]) -> List[_Tags]:
"""Collect matches from multiple files.
Expand Down Expand Up @@ -116,7 +113,6 @@ def _search_files(paths_source: Sequence[Path], regex_compiled: Pattern[str]) ->
"""Match owner and repository from a GitHub git origin URI."""


@beartype
def github_blame_url(clone_uri: str) -> str:
"""Format the blame URL.
Expand Down Expand Up @@ -166,7 +162,6 @@ class _CollectorRow(BaseModel):
source_file: str

@classmethod
@beartype
def from_code_tag(cls, code_tag: _CodeTag, last_edit: str, source_file: str) -> '_CollectorRow':
return cls(
tag_name=f'{code_tag.tag:>7}',
Expand All @@ -176,7 +171,6 @@ def from_code_tag(cls, code_tag: _CodeTag, last_edit: str, source_file: str) ->
)


@beartype
def _format_from_blame(
*,
collector_row: _CollectorRow,
Expand Down Expand Up @@ -210,7 +204,6 @@ def _format_from_blame(
return collector_row


@beartype
def _format_record(base_dir: Path, file_path: Path, comment: _CodeTag) -> _CollectorRow:
"""Format each table row for the code tag summary file. Include git permalink.
Expand Down Expand Up @@ -252,7 +245,6 @@ def _format_record(base_dir: Path, file_path: Path, comment: _CodeTag) -> _Colle
return collector_row


@beartype
def _format_report(
base_dir: Path,
code_tags: List[_Tags],
Expand Down Expand Up @@ -296,7 +288,6 @@ def _format_report(
return output


@beartype
def write_code_tag_file(
*,
path_tag_summary: Path,
Expand Down
4 changes: 0 additions & 4 deletions calcipy/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pathlib import Path
from types import ModuleType

from beartype import beartype
from beartype.typing import Any, Callable, Dict, List, Optional, Tuple, Union
from corallium.log import LOGGER, configure_logger
from invoke.collection import Collection as InvokeCollection # noqa: TID251
Expand Down Expand Up @@ -36,7 +35,6 @@ class GlobalTaskOptions(BaseModel):
"""Continue task execution regardless of failure."""


@beartype
def _configure_task_logger(ctx: Context) -> None: # pragma: no cover
"""Configure the logger based on task context."""
verbose = ctx.config.gto.verbose
Expand All @@ -46,7 +44,6 @@ def _configure_task_logger(ctx: Context) -> None: # pragma: no cover
configure_logger(log_level=log_level)


@beartype
def _run_task(func: Any, ctx: Context, *args: Any, show_task_info: bool, **kwargs: Any) -> Any: # pragma: no cover
"""Run the task function with optional logging."""
if show_task_info:
Expand All @@ -63,7 +60,6 @@ def _run_task(func: Any, ctx: Context, *args: Any, show_task_info: bool, **kwarg
return result


@beartype
def _wrapped_task(ctx: Context, *args: Any, func: Any, show_task_info: bool, **kwargs: Any) -> Any: # pragma: no cover
"""Wrap task with extended logic."""
try:
Expand Down
2 changes: 0 additions & 2 deletions calcipy/dot_dict/_dot_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
"""

from beartype import beartype
from beartype.typing import Any, Dict, Union
from box import Box

DdictType = Union[Dict[str, Any], Box]
"""Return type from `ddict()`."""


@beartype
def ddict(**kwargs: Dict[str, Any]) -> DdictType:
"""Return a dotted dictionary that can also be accessed normally.
Expand Down
2 changes: 0 additions & 2 deletions calcipy/experiments/bump_programmatically.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import griffe
import semver
from beartype import beartype
from corallium.log import LOGGER
from griffe.exceptions import BuiltinModuleError


@beartype
def bump_tag(*, pkg_name: str, tag: str, tag_prefix: str) -> str:
"""Make a SemVer minor bump using `griffe` if there were any breaking changes.
Expand Down
3 changes: 0 additions & 3 deletions calcipy/experiments/check_duplicate_test_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
import ast
from pathlib import Path

from beartype import beartype
from beartype.typing import List, Union
from corallium.log import LOGGER


@beartype
def _show_info(function: Union[ast.FunctionDef, ast.AsyncFunctionDef]) -> None:
"""Print info about the function."""
LOGGER.info('> name', name=function.name)
if function.args.args:
LOGGER.info('\t args', args=function.args.args)


@beartype
def run(test_path: Path) -> List[str]: # noqa: C901 # pylint: disable=too-complex
"""Check for duplicates in the test suite.
Expand Down
7 changes: 1 addition & 6 deletions calcipy/file_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
from collections import defaultdict
from pathlib import Path

from beartype import beartype
from beartype.typing import Dict, List, Optional
from corallium.log import LOGGER
from corallium.shell import capture_shell


@beartype
def _zsplit(stdout: str) -> List[str]:
"""Split output from git when used with `-z`."""
return [item for item in stdout.split('\0') if item]


@beartype
def _get_all_files(*, cwd: Path) -> List[str]:
"""Get all files using git. Modified `pre_commit.git.get_all_files` to accept `cwd`.
Expand All @@ -31,7 +28,6 @@ def _get_all_files(*, cwd: Path) -> List[str]:
return _zsplit(capture_shell('git ls-files -z', cwd=cwd))


@beartype
def _filter_files(rel_filepaths: List[str], ignore_patterns: List[str]) -> List[str]:
"""Filter a list of string file paths with specified ignore patterns in glob syntax.
Expand All @@ -53,7 +49,6 @@ def _filter_files(rel_filepaths: List[str], ignore_patterns: List[str]) -> List[
return rel_filepaths


@beartype
def find_project_files(path_project: Path, ignore_patterns: List[str]) -> List[Path]:
"""Find project files in git version control.
Expand All @@ -80,7 +75,7 @@ def find_project_files(path_project: Path, ignore_patterns: List[str]) -> List[P


# TODO: Consider adding a configuration item for ignore_patterns
@beartype

def find_project_files_by_suffix(
path_project: Path,
*,
Expand Down
3 changes: 0 additions & 3 deletions calcipy/invoke_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from os import environ
from pathlib import Path

from beartype import beartype
from beartype.typing import Any, Optional
from corallium.file_helpers import COPIER_ANSWERS, read_yaml_file
from invoke.context import Context
Expand All @@ -24,7 +23,6 @@ def use_pty() -> bool:
return not environ.get('GITHUB_ACTION')


@beartype
def run(ctx: Context, *run_args: Any, **run_kwargs: Any) -> Optional[Result]:
"""Wrap invoke.run to run within the `working_dir`."""
working_dir = '.'
Expand All @@ -45,7 +43,6 @@ def get_project_path() -> Path:
return Path.cwd()


@beartype
def get_doc_subdir(path_project: Optional[Path] = None) -> Path:
"""Retrieve the documentation directory from the copier answer file.
Expand Down
8 changes: 0 additions & 8 deletions calcipy/md_writer/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import re
from pathlib import Path

from beartype import beartype
from beartype.typing import Any, Callable, Dict, List, Optional
from corallium.file_helpers import read_lines
from corallium.log import LOGGER
Expand Down Expand Up @@ -46,7 +45,6 @@ def change_end(self) -> None:
if self.state == self.state_template:
self.state = self.state_other

@beartype
def parse(
self,
lines: List[str],
Expand All @@ -69,7 +67,6 @@ def parse(
updated_lines.extend(self._parse_line(line, handler_lookup, path_file))
return updated_lines

@beartype
def _parse_line(
self,
line: str,
Expand Down Expand Up @@ -114,7 +111,6 @@ def _parse_line(
"""Regex for extracting the variable from an HTML code comment."""


@beartype
def _parse_var_comment(line: str, matcher: str = _VAR_COMMENT_HTML) -> Dict[str, str]:
"""Parse the variable from a matching comment.
Expand All @@ -132,7 +128,6 @@ def _parse_var_comment(line: str, matcher: str = _VAR_COMMENT_HTML) -> Dict[str,
return {}


@beartype
def _handle_source_file(line: str, path_file: Path) -> List[str]:
"""Replace commented sections in README with linked file contents.
Expand All @@ -157,7 +152,6 @@ def _handle_source_file(line: str, path_file: Path) -> List[str]:
return [line_start, *lines_source, line_end]


@beartype
def _format_cov_table(coverage_data: Dict[str, Any]) -> List[str]:
"""Format code coverage data table as markdown.
Expand Down Expand Up @@ -195,7 +189,6 @@ def _format_cov_table(coverage_data: Dict[str, Any]) -> List[str]:
return lines_table


@beartype
def _handle_coverage(line: str, _path_file: Path, path_coverage: Optional[Path] = None) -> List[str]:
"""Read the coverage.json file and write a Markdown table to the README file.
Expand All @@ -221,7 +214,6 @@ def _handle_coverage(line: str, _path_file: Path, path_coverage: Optional[Path]
return [line, *lines_cov, line_end]


@beartype
def write_template_formatted_md_sections(
handler_lookup: Optional[HandlerLookupT] = None,
paths_md: Optional[List[Path]] = None,
Expand Down
Loading

0 comments on commit 97e09c8

Please sign in to comment.