django-stubs icon indicating copy to clipboard operation
django-stubs copied to clipboard

Replace TypeAlias `_ClassLevelWidgetT` with descriptor `_WidgetTypeOrInstance`

Open michalpokusa opened this issue 6 months ago • 11 comments

I have made things!

Related issues

None I could find.

This change allows for recognizing when .widget is used on Field instance and when on the type itself, allowing for different type annotations in each case.

image image image

Why even bother? Example: Currently this correct code does not recognize is_required and attrs on field.widget, because it might be a type and not an instance. image

After the change all types are correctly inferred, and syntax highlighting works as expected: image

I hope you find it worth adding.

michalpokusa avatar Apr 21 '25 15:04 michalpokusa