(I emailed Eric about this directly, but I thought it might be worth adding my feedback here too, I know it might be too late to alter the PEP, but think could still be helpful to document this issue)

Pydantic has supported the "Alternate Form" of dataclass transforms for a while which is supported by pyright.

As well as helping lots of people (I assume - happy people don't create issues, and I don't use pyright/pylance/vscode), we have had some issues with the "feature", see here.

In summary: pydantic has a BaseSettings type which users inherit from to manage settings, fields are defined on a class, then can be configured using environment variables and other external sources.

Because of this you can legitimately use "settings = Settings()" even when your Settings class has required fields - because they're filled from env variables.

The problem is that dataclass transforms apply to BaseSettings, and therefore Settings because BaseSettings inherits from BaseModel (which is marked with the decorator), so users get an error from pyright on "settings = Settings()" saying required fields are missing.

It would be great if there was a way to switch off dataclass transforms on some subclasses. The easiest way for users would be another magic decorator which marked the class (and its subclasses) as "not dataclass-like", but I'd be happy with any way to achieve this, e.g. a kwarg to dataclass_transform.

Samuel

--

Samuel Colvin


On Wed, 6 Apr 2022 at 07:39, Erik De Bonte via Typing-sig <typing-sig@python.org> wrote:

> So in the typeshed stubs this should have the full specification, and we should update this whenever we've agreed on a new keyword argument.

 

That makes sense. I actually didn’t realize that there was a stub file for typing.py. :) I also didn’t realize that keyword args and kwargs could be passed in all mixed together.

 

Thanks for explaining.

 

-Erik

 

_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/
Member address: samcolvin@gmail.com