Skip to content

Fix type hints#9

Open
riscjh wants to merge 1 commit intomasterfrom
fix-decorator-typing
Open

Fix type hints#9
riscjh wants to merge 1 commit intomasterfrom
fix-decorator-typing

Conversation

@riscjh
Copy link

@riscjh riscjh commented Mar 3, 2026

No description provided.

@github-actions
Copy link

github-actions bot commented Mar 3, 2026

Test Results

38 tests  ±0   38 ✅ ±0   0s ⏱️ ±0s
 1 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 22706e7. ± Comparison against base commit f5aff3a.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR focuses on improving type hints around log_decorator and related exports to reduce/avoid mypy ignores and make the decorator easier to type-check across the package.

Changes:

  • Adds ParamSpec/overload-based typing to log_decorator, and types wrapper arguments.
  • Removes a mypy ignore on partial(log_decorator, ...) usage.
  • Updates public exports / changelog and adds typing_extensions dependency.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/risclog/logging/log.py Removes type: ignore on partial(log_decorator, ...) now that log_decorator has improved typing.
src/risclog/logging/decorators.py Introduces overloads + ParamSpec typing for log_decorator and wrapper argument typing.
src/risclog/logging/__init__.py Adjusts how log_decorator is re-exported and simplifies type aliases.
setup.py Adds typing_extensions to support ParamSpec on older Python versions.
CHANGES.rst Records the type-hint fix in the unreleased section.
Comments suppressed due to low confidence (3)

src/risclog/logging/decorators.py:68

  • The async branch’s wrapper is annotated as returning Any, but for an async def input function the decorated callable’s return type should remain an awaitable of the original awaited result. With the current Callable[P, R] overload, R will be inferred as a Coroutine[...], and async def wrapper(...) -> Any does not match that and loses type information for callers. Consider adding a dedicated overload for async callables (e.g., Callable[P, Awaitable[T]] -> Callable[P, Awaitable[T]]) and typing the async wrapper to preserve T.
    if inspect.iscoroutinefunction(func):

        @wraps(func)
        async def wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
            if not logging.getLogger(logger.name).isEnabledFor(logging.DEBUG):

src/risclog/logging/decorators.py:192

  • return cast(Callable[P, R], wrapper) is currently masking a real type mismatch between the sync and async wrapper implementations (especially for coroutine functions). This makes the public type signature look correct while type checkers can’t validate it. After splitting sync/async overloads, return the correctly typed wrapper without a broad cast (or only cast within the specific branch where it’s proven safe).
    return cast(Callable[P, R], wrapper)

src/risclog/logging/init.py:4

  • Redundant aliasing: from ... import log_decorator as log_decorator can be simplified to from ... import log_decorator for clarity (the file already uses aliases only when names differ, e.g., getLogger as logger).
from risclog.logging.decorators import log_decorator as log_decorator
from risclog.logging.log import HybridLogger, get_logger as old_get_logger

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants