sbdchd / django-types

:doughnut: Type stubs for Django
MIT License
188 stars 62 forks source link

`null` on Foreign* is typed wrong #101

Closed antifuchs closed 2 years ago

antifuchs commented 2 years ago

The null field on ForeignKey and ForeignObject should accept bool values (so you can set null=True on fields without type errors. Currently, it only accepts Literal[False], so you can turn nullability off explicitly (which is the default anyway), but not on.

The django-stubs repo has the correct type signature for this property, and doesn't seem to have had the problem previously... is the fix here just to do whatever django-stubs does?

benesch commented 2 years ago

is the fix here just to do whatever django-stubs does?

Almost surely, and @sbdchd has been wonderful about merging my PRs in the past, so I'd say send it up!

bellini666 commented 2 years ago

@antifuchs it is actually typed correctly, the __new__ method is being overloaded.

If you are typing the foreignkey by yourself you may be falling into the same trap as this issue. Take a look at my comments there (specially the first reply) that might solve your issue.

antifuchs commented 2 years ago

Agh, that makes sense - I missed that the field is explicitly typed to be non-optional. Changing that does fix the type error (it's just a bit of a confusing type error from pyrite).