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

Signature of decorated function is not type checked by mypy #504

Open
truenicoco opened this issue Jul 23, 2023 · 3 comments · May be fixed by #508
Open

Signature of decorated function is not type checked by mypy #504

truenicoco opened this issue Jul 23, 2023 · 3 comments · May be fixed by #508

Comments

@truenicoco
Copy link

The following has mypy (expectedly) failing with error: Argument 1 to "f1" has incompatible type "int"; expected "str" [arg-type]

async def f1(x: str, y: int) -> str:
    return x + str(y)


async def main():
    await f1(1, 1)

But decorating f1 with @alru_cache prevents mypy from detecting any issue.

@Dreamsorcerer
Copy link
Member

Yes, it currently only types the return type correctly. It would need updating to use ParamSpec to type check the parameters.

@Dreamsorcerer
Copy link
Member

I've started #508 for this, but it's not working for methods correctly, not sure what's gone wrong there. It also results in type errors for partial() as mypy/typeshed don't fully support it yet.

If anyone wants to try and make any fixes, that'd be great.

@rkjdid
Copy link

rkjdid commented Oct 26, 2023

may be related https://youtrack.jetbrains.com/issue/PY-23067/Pycharm-not-picking-function-metadata-from-functools.wraps-with-methods#focus=Comments-27-6431674.0-0

I was having issues like this with (some) decorators in jetbrain's ide, the "preserved_signature" decorator on decorator fixes it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants