Skip to content

Commit

Permalink
Merge pull request #133 from jorenham/feature/mypy
Browse files Browse the repository at this point in the history
Preliminary mypy support
  • Loading branch information
jorenham authored Aug 5, 2024
2 parents b62a8d8 + 7bc669a commit 613cbf9
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 147 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"git.branchProtection": ["master"],
"githubPullRequests.overrideDefaultBranch": "dev"
"githubPullRequests.overrideDefaultBranch": "dev",
"mypy-type-checker.args": [
"--config-file=pyproject.toml"
]
}
28 changes: 10 additions & 18 deletions optype/_can.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# mypy: disable-error-code="override"

from __future__ import annotations

import sys
Expand Down Expand Up @@ -168,7 +170,7 @@ class CanFormat(Protocol[_StrT_contra, _StrT_co]):
or `str` subtypes. Note that `format()` *does not* upcast `Y` to `str`.
"""
@override
def __format__(self, fmt: _StrT_contra, /) -> _StrT_co: ...
def __format__(self, fmt: _StrT_contra, /) -> _StrT_co: ... # type: ignore[override]


# Iteration
Expand Down Expand Up @@ -310,23 +312,23 @@ def __call__(self, /, *args: _P.args, **kwargs: _P.kwargs) -> _AnyT_co: ...
@set_module('optype')
@runtime_checkable
class CanGetattr(Protocol[_StrT_contra, _AnyT_co]):
def __getattr__(self, name: _StrT_contra, /) -> _AnyT_co: ...
def __getattr__(self, name: _StrT_contra, /) -> _AnyT_co: ... # type: ignore[misc]


@set_module('optype')
@runtime_checkable
class CanGetattribute(Protocol[_StrT_contra, _AnyT_co]):
"""Note that `isinstance(x, CanGetattribute)` is always `True`."""
@override
def __getattribute__(self, name: _StrT_contra, /) -> _AnyT_co: ...
def __getattribute__(self, name: _StrT_contra, /) -> _AnyT_co: ... # type: ignore[misc]


@set_module('optype')
@runtime_checkable
class CanSetattr(Protocol[_StrT_contra, _AnyT_contra]):
"""Note that `isinstance(x, CanSetattr)` is always true."""
@override
def __setattr__(
def __setattr__( # type: ignore[misc]
self,
name: _StrT_contra,
value: _AnyT_contra,
Expand Down Expand Up @@ -539,12 +541,7 @@ def __pow__(self, exp: _T_contra, mod: None = ..., /) -> _T_co: ...
@set_module('optype')
@runtime_checkable
class CanPow3(Protocol[_T_contra, _V_contra, _AnyIntT_co]):
def __pow__(
self,
exp: _T_contra,
mod: _V_contra,
/,
) -> _AnyIntT_co: ...
def __pow__(self, exp: _T_contra, mod: _V_contra, /) -> _AnyIntT_co: ...


@set_module('optype')
Expand All @@ -559,12 +556,7 @@ def __pow__(self, exp: _T_contra, /) -> _T_co: ...
@overload
def __pow__(self, exp: _T_contra, mod: None = ..., /) -> _T_co: ...
@overload
def __pow__(
self,
exp: _T_contra,
mod: _AnyIntT_contra,
/,
) -> _AnyIntT_co: ...
def __pow__(self, exp: _T_contra, mod: _V_contra, /) -> _AnyIntT_co: ...


@set_module('optype')
Expand Down Expand Up @@ -1143,6 +1135,6 @@ class CanAwait(Protocol[_T_co]):
# impossible to type. In practice, typecheckers work around that, by
# accepting the lie called `collections.abc.Generator`...
@overload
def __await__(self: CanAwait[None], /) -> CanNext[_FutureOrNone]: ...
@overload
def __await__(self: CanAwait[_T_co], /) -> _AsyncGen[_T_co]: ...
@overload
def __await__(self: CanAwait[None], /) -> CanNext[_FutureOrNone]: ...
4 changes: 3 additions & 1 deletion optype/_do.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# mypy: disable-error-code="assignment"

from __future__ import annotations

import math as _math
Expand Down Expand Up @@ -57,7 +59,7 @@
# callables

if _sys.version_info >= (3, 11):
do_call: _d.DoesCall = _o.call
do_call: _d.DoesCall = _o.call # type: ignore[attr-defined]
else:
_Pss_call = ParamSpec('_Pss_call')
_R_call = TypeVar('_R_call')
Expand Down
Loading

0 comments on commit 613cbf9

Please sign in to comment.