Skip to content

Fixes that mypy plugin was failing on calling a typeclass without arguments #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ We follow Semantic Versions since the `0.1.0` release.
- Fixes that types referenced in multiple typeclasses
were not handling `Supports` properly #249
- Fixes typing bug with `ABC` and mutable typeclass signature #259
- Fixes that `mypy` plugin was failing
on calling a typeclass without arguments #270


## Version 0.3.0
Expand Down
2 changes: 1 addition & 1 deletion classes/contrib/mypy/features/typeclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def call_signature(ctx: MethodSigContext) -> CallableType:
assert isinstance(ctx.type, Instance)

real_signature = ctx.type.args[1]
if not isinstance(real_signature, CallableType):
if not isinstance(real_signature, CallableType) or not ctx.args[0]:
return ctx.default_signature

passed_type = ctx.api.expr_checker.accept(ctx.args[0][0]) # type: ignore
Expand Down
12 changes: 12 additions & 0 deletions typesafety/test_typeclass/test__call__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,15 @@
some(ac) # ok
some(bc) # ok
some(abc) # ok


- case: typeclass_call_zero_args_regression270
disable_cache: false
main: |
from classes import typeclass

@typeclass
def some(instance) -> int:
...

some() # E: Missing positional argument "instance" in call to "__call__" of "_TypeClass"