Add a constant holding `core_schema.any_schema()` value
I would like the following code more but it will always call core_schema.any_schema()
content_core_schema = schema.get('schema', core_schema.any_schema())
It would be nice to have a constant like core_schema.DEFAULT_SCHEMA that will hold this value and allow the above to be as efficient as if..in.
Originally posted by @lig in https://github.com/pydantic/pydantic/pull/6715#discussion_r1265881851
Selected Assignee: @lig
I can do it myself
I don’t think it’s worth it. Schema building should not be happening in a hot loop, and diverging from all other schema functions is not worth saving the 2 parentheses characters.
Well, this is about saving a call to core_schema.any_schema() in case you need it as a default value. See the original case https://github.com/pydantic/pydantic/pull/6715#discussion_r1265881851
Having such a constant allows using it in constructs like schema.get('schema', core_schema.DEFAULT_SCHEMA) instead of schema['schema'] if 'schema' in schema else core_schema.any_schema(). Using core_schema.any_schema() in a former results in an extra function call.
Why not schema.get('schema', core_schema.any_schema())?
Fixed by https://github.com/pydantic/pydantic-core/pull/1394