Skip to content

dmypy gives up on trivial decorator #18940

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

Open
asottile-sentry opened this issue Apr 17, 2025 · 3 comments · May be fixed by #19072
Open

dmypy gives up on trivial decorator #18940

asottile-sentry opened this issue Apr 17, 2025 · 3 comments · May be fixed by #19072

Comments

@asottile-sentry
Copy link

Bug Report

seems dmypy is unable to suggest an annotation when a function is decorated even with a trivial decorator (likely as the implementation predates widespread ParamSpec usage)

I believe the fix is deleting this line?

and isinstance(ct.arg_types[0], TypeVarType)

To Reproduce

from typing import Callable

def dec[R, **P](f: Callable[P, R]) -> Callable[P, R]:
    return f

@dec
def f():
    print('hello world')
[mypy]
check_untyped_defs = true

Expected Behavior

$ dmypy check .
...
$ dmypy suggest t.f
() -> None

Actual Behavior

$ dmypy check .
...
$ dmypy suggest t.f
Object t.f is a decorator we can't handle

Your Environment

  • Mypy version used: 1.15.0
  • Mypy command-line flags: (see above)
  • Mypy configuration options from mypy.ini (and other config files): (see above)
  • Python version used: 3.13.1
@asottile-sentry asottile-sentry added the bug mypy got something wrong label Apr 17, 2025
@brianschubert brianschubert added feature topic-daemon dmypy and removed bug mypy got something wrong labels Apr 18, 2025
@Jdwashin9
Copy link

I can check it out.

@Jdwashin9 Jdwashin9 mentioned this issue Apr 18, 2025
@A5rocks
Copy link
Collaborator

A5rocks commented Apr 18, 2025

Note that the line you commented about is a special case for this decorator seemingly (I have not tested):

def f(x: T) -> T:
  return x

So as a workaround you could use that, especially if you're not using the paramspec to transform parameters!

@asottile-sentry
Copy link
Author

I could but I have no control over the particular decorator -- and the real one uses the ParamSpec

also would like to use @contextlib.contextmanager-based decorators as well but it looks like those might be more complicated 🤔

asottile-sentry added a commit to getsentry/sentry that referenced this issue Apr 22, 2025
first commit automated via
https://github.com/getsentry/auto-type-annotate

- I used these patches to mypy:
    - python/mypy#18948
- (the line mentioned in the issue commented out):
python/mypy#18940 (comment)
- and with this unreverted (coming soon!):
#89854

<!-- Describe your PR here. -->
andrewshie-sentry pushed a commit to getsentry/sentry that referenced this issue Apr 22, 2025
first commit automated via
https://github.com/getsentry/auto-type-annotate

- I used these patches to mypy:
    - python/mypy#18948
- (the line mentioned in the issue commented out):
python/mypy#18940 (comment)
- and with this unreverted (coming soon!):
#89854

<!-- Describe your PR here. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants