v2.11.0 2025-03-27
What's Changed
Packaging
- Re-enable memray related tests on Python 3.12+ by @Viicos in #11191
- Bump astral-sh/setup-uv from 4 to 5 by @dependabot in #11205
- Add a
check_pydantic_core_version()function by @Viicos in #11324 - Remove
greenletdevelopment dependency by @Viicos in #11351 - Bump ruff from 0.9.2 to 0.9.5 by @Viicos in #11407
- Improve release automation process by @austinyu in #11427
- Bump dawidd6/action-download-artifact from 8 to 9 by @dependabot in #11513
- Bump
pydantic-coreto v2.32.0 by @Viicos in #11567
New Features
- Support unsubstituted type variables with both a default and a bound or constraints by @FyZzyss in #10789
- Add a
default_factory_takes_validated_dataproperty toFieldInfoby @Viicos in #11034 - Raise a better error when a generic alias is used inside
type[]by @Viicos in #11088 - Properly support PEP 695 generics syntax by @Viicos in #11189
- Properly support type variable defaults by @Viicos in #11332
- Add support for validating v6, v7, v8 UUIDs by @astei in #11436
- Improve alias configuration APIs by @sydney-runkle in #11468
- Add experimental support for free threading by @Viicos in #11516
- Add
encoded_string()method to the URL types by @YassinNouh21 in #11580 - Add support for
defer_buildwith@validate_calldecorator by @Viicos in #11584 - Allow
@with_configdecorator to be used with keyword arguments by @Viicos in #11608 - Simplify customization of default value inclusion in JSON Schema generation by @Viicos in #11634
- Add
generate_arguments_schema()function by @Viicos in #11572
Changes
- Rework
create_modelfield definitions format by @Viicos in #11032 - Raise a deprecation warning when a field is annotated as final with a default value by @Viicos in #11168
- Deprecate accessing
model_fieldsandmodel_computed_fieldson instances by @Viicos in #11169 - Move core schema generation logic for path types inside the
GenerateSchemaclass by @sydney-runkle in #10846 - Move
Mappingschema gen toGenerateSchemato complete removal ofprepare_annotations_for_known_typeworkaround by @sydney-runkle in #11247 - Remove Python 3.8 Support by @sydney-runkle in #11258
- Optimize calls to
get_type_refby @Viicos in #10863 - Disable
pydantic-corecore schema validation by @sydney-runkle in #11271
Performance
- Only evaluate
FieldInfoannotations if required during schema building by @Viicos in #10769 - Improve
__setattr__performance of Pydantic models by caching setter functions by @MarkusSintonen in #10868 - Improve annotation application performance by @Viicos in #11186
- Improve performance of
_typing_extramodule by @Viicos in #11255 - Refactor and optimize schema cleaning logic by @Viicos in #11244
- Create a single dictionary when creating a
CoreConfiginstance by @sydney-runkle in #11384 - Reuse cached core schemas for parametrized generic Pydantic models by @MarkusSintonen in #11434
Fixes
- Add validation tests for
_internal/_validators.pyby @tkasuz in #10763 - Subclass all single host url classes from
AnyUrlto preserve behavior from v2.9 by @sydney-runkle in #10856 - Improve
TypeAdapterinstance repr by @sydney-runkle in #10872 - Use the correct frame when instantiating a parametrized
TypeAdapterby @Viicos in #10893 - Relax check for validated data in default factory utils by @sydney-runkle in #10909
- Fix type checking issue with
model_fieldsandmodel_computed_fieldsby @sydney-runkle in #10911 - Use the parent configuration during schema generation for stdlib dataclasses by @sydney-runkle in #10928
- Use the globals of the function when evaluating the return type of serializers and computed_fields by @Viicos in #10929
- Fix url constraint application by @sydney-runkle in #10922
- Fix URL equality with different validation methods by @sydney-runkle in #10934
- Fix JSON schema title when specified as
''by @sydney-runkle in #10936 - Do not evaluate annotations for private fields by @Viicos in #10962
- Support serialization as any for
Secrettypes andUrltypes by @sydney-runkle in #10947 - Fix type hint of
Field.defaultto be compatible with Python 3.8 and 3.9 by @Viicos in #10972 - hashing support for urls by @sydney-runkle in #10975
- Hide
BaseModel.__replace__definition from type checkers by @Viicos in #10979 - Set fields when
defer_buildis set on Pydantic dataclasses by @Viicos in #10984 - Do not resolve the JSON Schema reference for
dictcore schema keys by @Viicos in #10989 - Use the globals of the function when evaluating the return type for
PlainSerializerandWrapSerializerfunctions by @Viicos in #11008 - Fix host required enforcement for urls to be compatible with v2.9 behavior by @sydney-runkle in #11027
- Fix url json schema in
serializationmode by @sydney-runkle in #11035 - Fix for comparison of AnyUrl objects by @alexprabhat99 in #11082
- Properly fetch PEP 695 type params for functions, do not fetch annotations from signature by @Viicos in #11093
- Infer final fields with a default value as class variables in the mypy plugin by @Viicos in #11121
- Recursively unpack
Literalvalues if using PEP 695 type aliases by @Viicos in #11114 - Override
__subclasscheck__onModelMetaclassto avoid memory leak and performance issues by @Viicos in #11116 - Include JSON Schema input core schema in function schemas by @Viicos in #11085
- Add
lento_BaseUrlto avoid TypeError by @Kharianne in #11111 - Make sure the type reference is removed from the seen references by @Viicos in #11143
- Add FastAPI and SQLModel to third-party tests by @sydney-runkle in #11044
- Improve discriminated union error message for invalid union variants by @Viicos in #11161
- Unpack PEP 695 type aliases if using the
Annotatedform by @Viicos in #11109 - Remove custom MRO implementation of Pydantic models by @Viicos in #11184
- Add pandera third-party tests by @Viicos in #11193
- Add ODMantic third-party tests by @sydney-runkle in #11197
- Copy
WithJsonSchemaschema to avoid sharing mutated data by @thejcannon in #11014 - Do not cache parametrized models when in the process of parametrizing another model by @Viicos in #10704
- Add discriminated union related metadata entries to the
CoreMetadatadefinition by @Viicos in #11216 - Consolidate schema definitions logic in the
_Definitionsclass by @Viicos in #11208 - Fix url serialization for unions by @sydney-runkle in #11227
- Support initializing root model fields with values of the
roottype in the mypy plugin by @Viicos in #11212 - Move
dequeschema gen toGenerateSchemaclass by @sydney-runkle in #11239 - Fix various issues with dataclasses and
use_attribute_docstringsby @Viicos in #11246 - Only compute normalized decimal places if necessary in
decimal_places_validatorby @misrasaurabh1 in #11281 - Add support for
validation_aliasin the mypy plugin by @Viicos in #11295 - Fix JSON Schema reference collection with
"examples"keys by @Viicos in #11305 - Do not transform model serializer functions as class methods in the mypy plugin by @Viicos in #11298
- Fix url python serialization by @sydney-runkle in #11330
- Add additional allowed schemes for
ClickHouseDsnby @Maze21127 in #11319 - Coerce decimal constraints to
Decimalinstances by @Viicos in #11350 - Use the correct JSON Schema mode when handling function schemas by @Viicos in #11367
- Fix JSON Schema reference logic with
exampleskeys by @Viicos in #11366 - Improve exception message when encountering recursion errors during type evaluation by @Viicos in #11356
- Always include
additionalProperties: Truefor arbitrary dictionary schemas by @austinyu in #11392 - Expose
fallbackparameter in serialization methods by @Viicos in #11398 - Fix path serialization behavior by @sydney-runkle in #11416
- Do not reuse validators and serializers during model rebuild by @Viicos in #11429
- Collect model fields when rebuilding a model by @Viicos in #11388
- Allow cached properties to be altered on frozen models by @Viicos in #11432
- Fix tuple serialization for
Sequencetypes by @sydney-runkle in #11435 - Fix: do not check for
__get_validators__on classes where__get_pydantic_core_schema__is also defined by @tlambert03 in #11444 - Allow callable instances to be used as serializers by @Viicos in #11451
- Improve error thrown when overriding field with a property by @sydney-runkle in #11459
- Add BentoML and Semantic Kernel third-party tests by @Viicos in #11469
- Adding
langchainthird party tests by @sydney-runkle in #11474 - Fix JSON Schema generation with referenceable core schemas holding JSON metadata by @Viicos in #11475
- Support strict specification on union member types by @sydney-runkle in #11481
- Run Beanie third-party tests on a single Python version by @Viicos in #11502
- Implicitly set
validate_by_nametoTruewhenvalidate_by_aliasisFalseby @sydney-runkle in #11503 - Change type of
Anywhen synthesizingBaseSettings.__init__signature in the mypy plugin by @Viicos in #11497 - Use the
typing-inspectionlibrary by @Viicos in #11479 - Support type variable defaults referencing other type variables by @Viicos in #11520
- Fix
NotRequiredqualifier not taken into account in stringified annotation by @Viicos in #11559 - Allow generic typed dictionaries to be used for unpacked variadic keyword parameters by @Viicos in #11571
- Fix runtime error when computing model string representation involving cached properties and self-referenced models by @Viicos in #11579
- Preserve other steps when using the ellipsis in the pipeline API by @Viicos in #11626
- Fix deferred discriminator application logic by @Viicos in #11591
New Contributors
- @FyZzyss made their first contribution in #10789
- @tamird made their first contribution in #10948
- @felixxm made their first contribution in #11077
- @alexprabhat99 made their first contribution in #11082
- @Kharianne made their first contribution in #11111
- @mdaffad made their first contribution in #11177
- @thejcannon made their first contribution in #11014
- @thomasfrimannkoren made their first contribution in #11251
- @usernameMAI made their first contribution in #11275
- @ananiavito made their first contribution in #11302
- @pawamoy made their first contribution in #11311
- @Maze21127 made their first contribution in #11319
- @kauabh made their first contribution in #11369
- @jaceklaskowski made their first contribution in #11353
- @tmpbeing made their first contribution in #11375
- @petyosi made their first contribution in #11405
- @austinyu made their first contribution in #11392
- @mikeedjones made their first contribution in #11402
- @astei made their first contribution in #11436
- @dsayling made their first contribution in #11522
- @joren485 made their first contribution in #11547
- @cmenon12 made their first contribution in #11562
- @Jeukoh made their first contribution in #11611
Full Changelog: v2.10.6...v2.11.0