Is your feature request related to a problem? Please describe.
pyright doesn't mark decorator arguments as accessed.
Describe the solution you'd like
Mark imports or variables as accessed when they are passed as decorator arguments.
Additional context
As PEP 318 states, decorators support arguments. I.e. Django uses
from django.db.models.signals import post_save
from .models import User
@receiver(post_save, sender=User)
def signal_handler(sender, instance, *args, **kwargs):
pass
for it's synchronous signals. In this example neither post_save nor User are recognized as accessed in this context, but as they are accessed as arguments for the decorator, they should be marked as such.
Thanks for the bug report. It took me a while to figure out the problem because I wasn't able to repro it at first. There's an additional condition that needs to be met to repro the bug. The decorator method needs to be untyped. An untyped decorator is a very bad thing because it completely obscures the type of the function (or class) that it's decorating, which disables all type checking for that method or class. For that reason, I strongly encourage you to add the following settings to your pyrightconfig.json file:
"reportUntypedFunctionDecorator": "error",
"reportUntypedClassDecorator": "error",
And then I encourage you to add type definitions (via custom type stubs if necessary) for any decorators that you're using.
In any case, this bug is easy to fix, and it will be addressed in the next version of pyright.
This is now fixed in version 1.0.41, which I just published. Thanks again for the bug report!