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

type signature preservation does not support class arguments #18

Open
bmc-msft opened this issue Dec 31, 2020 · 3 comments
Open

type signature preservation does not support class arguments #18

bmc-msft opened this issue Dec 31, 2020 · 3 comments
Labels
bug Something isn't working priority-0-high This issue has a high priority

Comments

@bmc-msft
Copy link

Example source:

from memoization import cached
import inspect

class A:
    @cached(ttl=1)
    def b(self, name: str) -> int:
        return len(name) * 2

    def a(self) -> bool:
        return self.b('hello') == 10

Using mypy for the above example gives the error:

/tmp/as-class.py:10: error: Too few arguments for "b" of "A"
/tmp/as-class.py:10: error: Argument 1 to "b" of "A" has incompatible type "str"; expected "A"

If you comment out the @cached line, mypy gives the response:

Success: no issues found in 1 source file
@bmc-msft
Copy link
Author

bmc-msft commented Dec 31, 2020

Using the example I provided in #16, @cached preserves the arguments as I expected.

@pelson
Copy link

pelson commented Jan 6, 2021

Came across this one today also.

@lonelyenvoy lonelyenvoy added bug Something isn't working priority-0-high This issue has a high priority labels Jan 7, 2021
@lonelyenvoy
Copy link
Owner

lonelyenvoy commented Aug 1, 2021

According to Guido van Rossum (python/typing#824), this should be a longstanding issue in mypy (python/mypy#10805). Until now, I did not find any workaround, but I will continue to work on it.

If anyone encounters this issue, I recommend using @bmc-msft's way to disable the cache before mypy checks and enable it afterwards.

@lonelyenvoy lonelyenvoy pinned this issue Aug 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-0-high This issue has a high priority
Projects
None yet
Development

No branches or pull requests

3 participants