Skip to content
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

Mypy complains when currying a class #1476

Open
swoutch opened this issue Sep 2, 2022 · 4 comments
Open

Mypy complains when currying a class #1476

swoutch opened this issue Sep 2, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@swoutch
Copy link

swoutch commented Sep 2, 2022

Bug report

Hi, I'm trying to curry a class constructor, but mypy complains

What's wrong

# main.py
from returns.curry import curry


@curry
class Person:
    def __init__(self, name: str, age: int):
        self.name = name
        self.age = age

Person("bob")(33)
$ mypy main.py            
main.py:10: error: Missing positional argument "age" in call to "Person"
main.py:10: error: "Person" not callable
Found 2 errors in 1 file (checked 1 source file)

Here is my mypy.ini file:

[mypy]
plugins =
  returns.contrib.mypy.returns_plugin

How is that should be

mypy should not report any error

System information

  • python version: 3.10.4

  • returns version: 0.19.0

  • mypy version: 0.971

  • hypothesis version (if any): not installed

  • pytest version (if any): not installed

@swoutch swoutch added the bug Something isn't working label Sep 2, 2022
@sobolevn
Copy link
Member

sobolevn commented Sep 2, 2022

This is a known issue.

@swoutch
Copy link
Author

swoutch commented Sep 2, 2022

This is a known issue.

Thank you for this piece of information :)

@sobolevn
Copy link
Member

sobolevn commented Sep 2, 2022

Try this:

reveal_type(Test) # N: Revealed type is "Overload(def (arg: builtins.int) -> def (other: builtins.str) -> ex.Test, def (arg: builtins.int, other: builtins.str) -> ex.Test)"

@swoutch
Copy link
Author

swoutch commented Sep 2, 2022

mypy doesn't complain about that:

from returns.curry import curry


class Test(object):
    @curry
    def __init__(self, arg: int, other: str) -> None:
        ...

Test(1)

But does complain about that:

Test(1)("")
$ mypy main.py
main.py:9: error: "Test" not callable
Found 1 error in 1 file (checked 1 source file)

In both cases, python doesn't seem to like the curry on __init__:

$ python main.py
Traceback (most recent call last):
  File "/Users/jul/dev/bug-curry/main.py", line 9, in <module>
    Test(1)
TypeError: __init__() should return None, not 'function'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants