dry-python / returns

Make your functions return something meaningful, typed, and safe!
https://returns.rtfd.io
BSD 2-Clause "Simplified" License
3.55k stars 116 forks source link

Mypy complains when currying a class #1476

Open swoutch opened 2 years ago

swoutch commented 2 years ago

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

sobolevn commented 2 years ago

This is a known issue.

swoutch commented 2 years ago

This is a known issue.

Thank you for this piece of information :)

sobolevn commented 2 years ago

Try this: https://github.com/dry-python/returns/blob/964479d79075ffac7808755fb63709eca0fe4933/typesafety/test_curry/test_curry/test_curry_arguments.yml#L75

swoutch commented 2 years ago

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'