sbdchd / django-types

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

pyright1.1.315 or 1.1.316 cause an UnknownArgumentType for all generics in fields/related.py #175

Open dolfandringa opened 1 year ago

dolfandringa commented 1 year ago

When creating a Django migration which contains

migrations.AddField(
            model_name="wall",
            name="epc",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="walls",
                to="epcs.epc",
            ),
        ),

pyright 1.1.315 and 1.1.316 complain

 error: Argument type is partially unknown
    Argument corresponds to parameter "field" in function "__init__"
    Argument type is "ForeignKey[Unknown]" (reportUnknownArgumentType)

This is because indeed db.models.fields.related.ForeignKey is defined as a Generic and pyright doesn't know what type this Generic points to, since that is encoded in the to="epcs.epc" bit which isn't even a fully importable module/class. This issue only surfaces now because I think 1.1.315 actually fixed a few bugs related to Generics as arguments in functions I think. The issue is that the stub does specify it as a generic, but pyright has no way of understanding the Django magic that tells it this one points to class ..epcs.models.EPC.

I don't know exactly what the solution is here, but pyright definitely doesn't like it.