Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Add autocomplete support for VS Code, via
dataclass_transform
#2721✨ Add autocomplete support for VS Code, via
dataclass_transform
#2721Changes from 6 commits
a8e2528
88fe649
d4c57c9
7c0adbb
c926ed4
a56e3e1
1bed0f7
f5fa6a2
ff06395
e9953a3
a379b86
a22eee9
3ceab48
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any possibility to add the
frozen
argument which should equalconfig.frozen or not config.allow_mutation
?I can't see how this is possible but @erictraut suggested it should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can pass frozen=True when constructing a class that derives from
ModelBase
, like this:That was based on a suggestion you made in our email discussion — or at least how I interpreted your suggestion. Did I understand you correctly?
All classes are assumed to be non-frozen unless otherwise specified. There is a request from the
attrs
maintainers to provide a way to specify afrozen_default
option so they can default tofrozen=True
if it is not specified. If that would also be useful for pydantic, it would bolster the case for adding it to the spec.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's awesome. I've just tried it and it's already working!
This looks great then, the only problem I can see is the type strictness/laxness which is being discussed on microsoft/pyright#1782
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EDIT: Dang it, I didn't see all your previous conversation above this message, I guess I had a stale window. Sorry.
EDIT 2: discard this message pretty much entirely, already covered above and below. 🤦 😂
Old message below:
I didn't see a way to do it from what I read in the spec.
If I understand correctly, it would be possible for Pyright (and the spec) to understand if the model was created like:
...which is currently not supported by pydantic (although I think sounds interesting).
What is currently supported by pydantic (but I understand not by Pyright nor the spec) is:
I'll wait for @erictraut's input in case it's possible to support pydantic's internal
class Config
in a way I didn't realize.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is actually supported in 1.8 @tiangolo 😉 Config arguments can now be passed as class kwargs thanks to @MrMrRobat's amazing work in #2356
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dang it again! 🤦 😂 pydantic has evolved so much and I haven't noticed everything! 😅
Thanks for the clarification @PrettyWood, that's awesome! 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this with v1.9 and Pyright does not seem to recognise
frozen
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, this probably needs a new issue.
I've no idea if this is something pydantic can help with, or an issue with pyright. @erictraut any idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#3545