Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ See [0Ver](https://0ver.org/).

### Bugfixes

- Fixes the `mypy` plugin crashing with `INTERNAL ERROR` when `dekind`
is called with an argument that is not a `KindN` instance;
now only the regular `arg-type` error is reported
- Relaxes `future` and `future_safe` decorator argument types from
`Coroutine` to `Awaitable`, so plain `async def` functions wrapping
another awaitable (instead of being coroutine functions themselves)
Expand Down
4 changes: 3 additions & 1 deletion returns/contrib/mypy/_features/kind.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ def dekind(ctx: FunctionContext) -> MypyType:
So, ``dekind(KindN[T, int])`` will fail.
"""
kind = get_proper_type(ctx.arg_types[0][0])
assert isinstance(kind, Instance) # mypy requires these lines
if not isinstance(kind, Instance) or not kind.args:
# Not a `KindN` instance: mypy already reports the `arg-type` error.
return ctx.default_return_type

kind_inst = get_proper_type(kind.args[0])

Expand Down
26 changes: 26 additions & 0 deletions typesafety/test_primitives/test_hkt/test_dekind/test_dekind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,29 @@
out: |
main:8: error: dekind must be used with Instance as the first type argument [misc]
main:8: note: Revealed type is "Any"


- case: dekind_wrong_non_kind_argument
disable_cache: false
main: |
from returns.primitives.hkt import dekind

reveal_type(dekind(1))
out: |
main:3: note: Revealed type is "Never"
main:3: error: Argument 1 to "dekind" has incompatible type "int"; expected "KindN[Never, Never, Never, Never]" [arg-type]


- case: dekind_wrong_typevar_argument
disable_cache: false
main: |
from typing import TypeVar
from returns.primitives.hkt import dekind

T = TypeVar('T')

def some(arg: T) -> None:
reveal_type(dekind(arg))
out: |
main:7: note: Revealed type is "Never"
main:7: error: Argument 1 to "dekind" has incompatible type "T"; expected "KindN[Never, Never, Never, Never]" [arg-type]
Loading