Giter Club home page Giter Club logo

Comments (1)

te25son avatar te25son commented on September 6, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.