djantic2 icon indicating copy to clipboard operation
djantic2 copied to clipboard

Pycharm highlights "Unexpected argument in ConfigDict

Open stuaxo opened this issue 8 months ago • 8 comments

For Djantic2 we need model_config = ConfigDict(model = ... , include = ....) pycharm flags this with a warning that model and include are not expected.

I think something needs doing to let the type system know that this is OK.

Image

stuaxo avatar May 13 '25 16:05 stuaxo

Since ConfigDict belongs to pydantic, could please let me know what version of pydantic you're running? I'm also assuming that you're running latest version of djantic2.

jonathan-s avatar May 13 '25 17:05 jonathan-s

Good point -

pydantic 2.11.4 djantic2 1.0.5

stuaxo avatar May 13 '25 21:05 stuaxo

I guess it does belong to pydantic, but I don't think they have a way of adding fields (I wish they did), so maybe djantic needs it it's own ConfigDict ?

stuaxo avatar May 20 '25 22:05 stuaxo

Another question, can you replicate this with mypy or similar? I appreciate that you're seeing this in pycharm. But pycharm is also proprietary so it would be good to know where this comes from more explicitly.

jonathan-s avatar May 21 '25 07:05 jonathan-s

Hey folks @stuaxo @jonathan-s I can confirm that the same happens on mypy. I was just now using this lib (which is awesome, by the way) and got the following:

mypy: Extra key "model" for TypedDict "ConfigDict"  [typeddict-unknown-key]

Versions of what I have here:

pydantic==2.11.1
Django==5.2
djantic2==1.0.5

The solution for now is to include a comment # type: ignore[typeddict-unknown-key].

mazulo avatar Jun 09 '25 00:06 mazulo

Thanks, the reason I didn't get to this is that I have yet to try mypy in a project.

I wonder what the solution is, should Djantic2 include it's own versions of these that have the extra type annotations ?

stuaxo avatar Jun 09 '25 14:06 stuaxo

@stuaxo I think that would be the most appropriate/fast solution. Right now I'm in a mess of job applications/interviews, but as soon as I get some time I can give it a shot. If it works well I can then open a PR for you all take a look

mazulo avatar Jun 12 '25 15:06 mazulo

@stuaxo I think that would be the most appropriate/fast solution. Right now I'm in a mess of job applications/interviews, but as soon as I get some time I can give it a shot. If it works well I can then open a PR for you all take a look

Yeah, that seems like a sensible approach, probably the djantic config dict should inherit from the pydantic.

jonathan-s avatar Jun 12 '25 15:06 jonathan-s