Skip to content

Commit f535bb5

Browse files
committed
Fixes CI
1 parent 23ed04b commit f535bb5

File tree

7 files changed

+31
-30
lines changed

7 files changed

+31
-30
lines changed

classes/_registry.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ def choose_registry( # noqa: WPS211
1515
instances: TypeRegistry,
1616
protocols: TypeRegistry,
1717
) -> TypeRegistry:
18-
""""""
18+
"""
19+
Returns the appropriate registry to store the passed type.
20+
21+
It depends on how ``instance`` method is used and also on the type itself.
22+
"""
1923
if is_protocol:
2024
return protocols
2125

classes/_typeclass.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,12 @@
114114
115115
See our `official docs <https://classes.readthedocs.io>`_ to learn more!
116116
"""
117-
118-
from abc import get_cache_token
119117
from functools import _find_impl # type: ignore # noqa: WPS450
120-
from types import MethodType
121118
from typing import ( # noqa: WPS235
122119
TYPE_CHECKING,
123120
Callable,
124121
Dict,
125122
Generic,
126-
NoReturn,
127123
Optional,
128124
Type,
129125
TypeVar,

classes/contrib/mypy/validation/validate_instance_args.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
@final
2121
class _ArgValidationContext(NamedTuple):
22-
""""""
22+
"""Context for instance arg validation."""
2323

2424
is_protocol: bool
2525
delegate: Optional[MypyType]
@@ -30,6 +30,14 @@ def check_type(
3030
passed_types: TupleType,
3131
ctx: MethodContext,
3232
) -> _ArgValidationContext:
33+
"""
34+
Checks that args to ``.instance`` method are correct.
35+
36+
We cannot use ``@overload`` on ``.instance`` because ``mypy``
37+
does not correctly handle ``ctx.api.fail`` on ``@overload`` items:
38+
it then tries new ones, which produce incorrect results.
39+
So, that's why we need this custom checker.
40+
"""
3341
passed_args = passed_types.items
3442

3543
is_protocol, protocol_check = _check_protocol_arg(passed_args[1], ctx)
@@ -72,10 +80,6 @@ def _check_delegate_arg(
7280
delegate: MypyType,
7381
ctx: MethodContext,
7482
) -> Tuple[Optional[MypyType], bool]:
75-
# TODO: maybe we need to inforce that `delegate` should be
76-
# similar to `runtime_type`?
77-
# For example, we can ask for subtypes of `runtime_type`.
78-
# However, motivation is not clear for now.
7983
if isinstance(delegate, FunctionLike) and delegate.is_type_obj():
8084
return delegate.items()[-1].ret_type, True
8185
return None, True

classes/contrib/mypy/validation/validate_runtime.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,18 @@ def check_instance_definition(
8585
ctx.context,
8686
)
8787

88-
return _RuntimeValidationContext(
89-
runtime_type=runtime_type,
90-
is_protocol=args_check.is_protocol,
91-
check_result=all([
92-
args_check.check_result,
93-
instance_check,
94-
95-
_check_runtime_protocol(
96-
runtime_type, ctx, is_protocol=args_check.is_protocol,
97-
),
98-
_check_concrete_generics(
99-
runtime_type, instance_type, args_check.delegate, ctx,
100-
),
101-
_check_tuple_size(instance_type, ctx),
102-
],
103-
))
88+
return _RuntimeValidationContext(runtime_type, args_check.is_protocol, all([
89+
args_check.check_result,
90+
instance_check,
91+
92+
_check_runtime_protocol(
93+
runtime_type, ctx, is_protocol=args_check.is_protocol,
94+
),
95+
_check_concrete_generics(
96+
runtime_type, instance_type, args_check.delegate, ctx,
97+
),
98+
_check_tuple_size(instance_type, ctx),
99+
]))
104100

105101

106102
def _check_runtime_protocol(

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ ignore = D100, D104, D401, W504, X100, WPS121, RST299, RST303, RST304, DAR103, D
3535

3636
per-file-ignores =
3737
classes/__init__.py: F401, WPS113, WPS436
38-
classes/_typeclass.py: WPS320
38+
classes/_typeclass.py: WPS320, WPS436
3939
# We need `assert`s to please mypy:
4040
classes/contrib/mypy/*.py: S101
4141
# There are multiple assert's in tests:
42-
tests/*.py: S101, WPS226, WPS431, WPS432, WPS436
42+
tests/*.py: S101, WPS202, WPS226, WPS431, WPS432, WPS436
4343

4444

4545
[isort]

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import pytest
21
from contextlib import contextmanager
32

3+
import pytest
4+
45

56
@pytest.fixture(scope='session')
67
def clear_cache():

tests/test_suppots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Sized, List
1+
from typing import List, Sized
22

33
import pytest
44

0 commit comments

Comments
 (0)