Skip to content

Commit

Permalink
type override better
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorpela committed Oct 17, 2022
1 parent 3f24308 commit a548f8b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ jobs:
run: pytest tests
- name: Run mypy
run: mypy overrides
- name: Run mypy static tests
- name: Run mypy static tests (Python=3.10)
if: matrix.python == '3.10'
run: ./check_mypy.sh
15 changes: 15 additions & 0 deletions mypy_passes/passing_rewrite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
""""Bug."""
from typing import Callable, TypeVar, ParamSpec

P = ParamSpec("P")
T = TypeVar("T")

try:
from overrides import override
except ModuleNotFoundError:

def override(func: Callable[P, T]) -> Callable[P, T]: # type: ignore[no-redef]
return func


print(override)
3 changes: 1 addition & 2 deletions overrides/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from overrides.final import final
else:
from typing import final
from overrides.overrides import __VERSION__, overrides
from overrides.overrides import __VERSION__, overrides, override

override = overrides

__all__ = [
"__VERSION__",
Expand Down
31 changes: 31 additions & 0 deletions overrides/overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,37 @@ def method(self):
)


@overload
def override(
method: None = None,
*,
check_signature: bool = True,
check_at_runtime: bool = False,
) -> _DecoratorMethod:
...


@overload
def override(
method: _WrappedMethod,
*,
check_signature: bool = True,
check_at_runtime: bool = False,
) -> _WrappedMethod:
...


def override(
method: Optional[_WrappedMethod] = None,
*,
check_signature: bool = True,
check_at_runtime: bool = False,
) -> Union[_DecoratorMethod, _WrappedMethod]:
return overrides(
method, check_signature=check_signature, check_at_runtime=check_at_runtime
)


def _overrides(
method: _WrappedMethod,
check_signature: bool,
Expand Down

0 comments on commit a548f8b

Please sign in to comment.