Comments (1)
After investigating the pydantic docs, it doesn't seem there's a possibility to skip only certain fields. Pydantic does offer a construct
method on all models that inherit from BaseModel
but simply creates the model without any validation.
It is possible to delay the validation until the JokeSingleSubmit
is called by using the construct method to build the joke base. So something like
joke = JokeBase.construct(**data)
However, this would make the use of match_type
less safe since the type hasn't been validated at this point. If the type is not valid, the method can raise a key error when converting the string to an enum in Type[self.type]
.
Of course, the type should never be invalid since it's coming directly from click which also checks that the input is valid 🤷♂️ Also the method is wrapped inside a @safe
decorator, so even it if fails, it won't display anything to the user unless the debug
flag is activated.
All in all, if we want to improve the performance slightly, while also having plenty of safety checks in place, we could simply use the construct method as mentioned above and delay the validation until the JokeSingleSubmit
or JokeTwopartSubmit
models are created.
from jokes.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jokes.