Skip to content

Commit a20da21

Browse files
sydney-runklehramezanisamuelcolvinAlexWaygood
authored
2.7.2 prep (#9515)
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com> Co-authored-by: Samuel Colvin <s@muelcolvin.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 2612947 commit a20da21

7 files changed

Lines changed: 243 additions & 218 deletions

File tree

HISTORY.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
## v2.7.2 (2024-05-28)
2+
3+
[GitHub release](https://github.com/pydantic/pydantic/releases/tag/v2.7.2)
4+
5+
### What's Changed
6+
7+
#### Packaging
8+
9+
* Bump `pydantic-core` to `v2.18.2` by @sydney-runkle in [#9515](https://github.com/pydantic/pydantic/pull/9515)
10+
11+
#### Fixes
12+
13+
* Replace `__spec__.parent` with `__package__` by @hramezani in [#9331](https://github.com/pydantic/pydantic/pull/9331)
14+
* Fix validation of `int`s with leading unary minus by @RajatRajdeep in [pydantic/pydantic-core#1291](https://github.com/pydantic/pydantic-core/pull/1291)
15+
* Fix `str` subclass validation for enums by @sydney-runkle in [pydantic/pydantic-core#1273]https://github.com/pydantic/pydantic-core/pull/1273
16+
* Support `BigInt`s in `Literal`s and `Enum`s by @samuelcolvin in [pydantic/pydantic-core#1297]https://github.com/pydantic/pydantic-core/pull/1297
17+
* Fix: uuid - allow `str` subclass as input by @davidhewitt in [pydantic/pydantic-core#1296]https://github.com/pydantic/pydantic-core/pull/1296
18+
119
## v2.7.1 (2024-04-23)
220

321
[GitHub release](https://github.com/pydantic/pydantic/releases/tag/v2.7.1)

docs/theme/announce.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<!-- the following line is displayed in the announcement bar -->
22
<!-- keep length under 164 characters (less HTML tags) to fit on 1280px desktop window -->
3-
<a href="https://docs.pydantic.dev/2.0/blog/pydantic-v2-final/">Pydantic V2</a> is here 🚀! Upgrading an existing app? See the <a href="https://docs.pydantic.dev/2.0/migration/">Migration Guide</a> for tips on essential changes from Pydantic V1!
3+
<b>We're live!</b> <a href="https://pydantic.dev/logfire">Pydantic Logfire</a> is out in open beta! 🎉<br>
4+
Logfire is a new observability tool for Python, from the creators of Pydantic, with great Pydantic support.
5+
Please try it, and tell us <a href="https://docs.pydantic.dev/logfire/help/">what you think</a>!

pdm.lock

Lines changed: 81 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pydantic/__init__.py

Lines changed: 130 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -220,145 +220,145 @@
220220

221221
# A mapping of {<member name>: (package, <module name>)} defining dynamic imports
222222
_dynamic_imports: 'dict[str, tuple[str, str]]' = {
223-
'dataclasses': (__package__, '__module__'),
223+
'dataclasses': (__spec__.parent, '__module__'),
224224
# functional validators
225-
'field_validator': (__package__, '.functional_validators'),
226-
'model_validator': (__package__, '.functional_validators'),
227-
'AfterValidator': (__package__, '.functional_validators'),
228-
'BeforeValidator': (__package__, '.functional_validators'),
229-
'PlainValidator': (__package__, '.functional_validators'),
230-
'WrapValidator': (__package__, '.functional_validators'),
231-
'SkipValidation': (__package__, '.functional_validators'),
232-
'InstanceOf': (__package__, '.functional_validators'),
225+
'field_validator': (__spec__.parent, '.functional_validators'),
226+
'model_validator': (__spec__.parent, '.functional_validators'),
227+
'AfterValidator': (__spec__.parent, '.functional_validators'),
228+
'BeforeValidator': (__spec__.parent, '.functional_validators'),
229+
'PlainValidator': (__spec__.parent, '.functional_validators'),
230+
'WrapValidator': (__spec__.parent, '.functional_validators'),
231+
'SkipValidation': (__spec__.parent, '.functional_validators'),
232+
'InstanceOf': (__spec__.parent, '.functional_validators'),
233233
# JSON Schema
234-
'WithJsonSchema': (__package__, '.json_schema'),
234+
'WithJsonSchema': (__spec__.parent, '.json_schema'),
235235
# functional serializers
236-
'field_serializer': (__package__, '.functional_serializers'),
237-
'model_serializer': (__package__, '.functional_serializers'),
238-
'PlainSerializer': (__package__, '.functional_serializers'),
239-
'SerializeAsAny': (__package__, '.functional_serializers'),
240-
'WrapSerializer': (__package__, '.functional_serializers'),
236+
'field_serializer': (__spec__.parent, '.functional_serializers'),
237+
'model_serializer': (__spec__.parent, '.functional_serializers'),
238+
'PlainSerializer': (__spec__.parent, '.functional_serializers'),
239+
'SerializeAsAny': (__spec__.parent, '.functional_serializers'),
240+
'WrapSerializer': (__spec__.parent, '.functional_serializers'),
241241
# config
242-
'ConfigDict': (__package__, '.config'),
243-
'with_config': (__package__, '.config'),
242+
'ConfigDict': (__spec__.parent, '.config'),
243+
'with_config': (__spec__.parent, '.config'),
244244
# validate call
245-
'validate_call': (__package__, '.validate_call_decorator'),
245+
'validate_call': (__spec__.parent, '.validate_call_decorator'),
246246
# errors
247-
'PydanticErrorCodes': (__package__, '.errors'),
248-
'PydanticUserError': (__package__, '.errors'),
249-
'PydanticSchemaGenerationError': (__package__, '.errors'),
250-
'PydanticImportError': (__package__, '.errors'),
251-
'PydanticUndefinedAnnotation': (__package__, '.errors'),
252-
'PydanticInvalidForJsonSchema': (__package__, '.errors'),
247+
'PydanticErrorCodes': (__spec__.parent, '.errors'),
248+
'PydanticUserError': (__spec__.parent, '.errors'),
249+
'PydanticSchemaGenerationError': (__spec__.parent, '.errors'),
250+
'PydanticImportError': (__spec__.parent, '.errors'),
251+
'PydanticUndefinedAnnotation': (__spec__.parent, '.errors'),
252+
'PydanticInvalidForJsonSchema': (__spec__.parent, '.errors'),
253253
# fields
254-
'Field': (__package__, '.fields'),
255-
'computed_field': (__package__, '.fields'),
256-
'PrivateAttr': (__package__, '.fields'),
254+
'Field': (__spec__.parent, '.fields'),
255+
'computed_field': (__spec__.parent, '.fields'),
256+
'PrivateAttr': (__spec__.parent, '.fields'),
257257
# alias
258-
'AliasChoices': (__package__, '.aliases'),
259-
'AliasGenerator': (__package__, '.aliases'),
260-
'AliasPath': (__package__, '.aliases'),
258+
'AliasChoices': (__spec__.parent, '.aliases'),
259+
'AliasGenerator': (__spec__.parent, '.aliases'),
260+
'AliasPath': (__spec__.parent, '.aliases'),
261261
# main
262-
'BaseModel': (__package__, '.main'),
263-
'create_model': (__package__, '.main'),
262+
'BaseModel': (__spec__.parent, '.main'),
263+
'create_model': (__spec__.parent, '.main'),
264264
# network
265-
'AnyUrl': (__package__, '.networks'),
266-
'AnyHttpUrl': (__package__, '.networks'),
267-
'FileUrl': (__package__, '.networks'),
268-
'HttpUrl': (__package__, '.networks'),
269-
'FtpUrl': (__package__, '.networks'),
270-
'WebsocketUrl': (__package__, '.networks'),
271-
'AnyWebsocketUrl': (__package__, '.networks'),
272-
'UrlConstraints': (__package__, '.networks'),
273-
'EmailStr': (__package__, '.networks'),
274-
'NameEmail': (__package__, '.networks'),
275-
'IPvAnyAddress': (__package__, '.networks'),
276-
'IPvAnyInterface': (__package__, '.networks'),
277-
'IPvAnyNetwork': (__package__, '.networks'),
278-
'PostgresDsn': (__package__, '.networks'),
279-
'CockroachDsn': (__package__, '.networks'),
280-
'AmqpDsn': (__package__, '.networks'),
281-
'RedisDsn': (__package__, '.networks'),
282-
'MongoDsn': (__package__, '.networks'),
283-
'KafkaDsn': (__package__, '.networks'),
284-
'NatsDsn': (__package__, '.networks'),
285-
'MySQLDsn': (__package__, '.networks'),
286-
'MariaDBDsn': (__package__, '.networks'),
287-
'ClickHouseDsn': (__package__, '.networks'),
288-
'validate_email': (__package__, '.networks'),
265+
'AnyUrl': (__spec__.parent, '.networks'),
266+
'AnyHttpUrl': (__spec__.parent, '.networks'),
267+
'FileUrl': (__spec__.parent, '.networks'),
268+
'HttpUrl': (__spec__.parent, '.networks'),
269+
'FtpUrl': (__spec__.parent, '.networks'),
270+
'WebsocketUrl': (__spec__.parent, '.networks'),
271+
'AnyWebsocketUrl': (__spec__.parent, '.networks'),
272+
'UrlConstraints': (__spec__.parent, '.networks'),
273+
'EmailStr': (__spec__.parent, '.networks'),
274+
'NameEmail': (__spec__.parent, '.networks'),
275+
'IPvAnyAddress': (__spec__.parent, '.networks'),
276+
'IPvAnyInterface': (__spec__.parent, '.networks'),
277+
'IPvAnyNetwork': (__spec__.parent, '.networks'),
278+
'PostgresDsn': (__spec__.parent, '.networks'),
279+
'CockroachDsn': (__spec__.parent, '.networks'),
280+
'AmqpDsn': (__spec__.parent, '.networks'),
281+
'RedisDsn': (__spec__.parent, '.networks'),
282+
'MongoDsn': (__spec__.parent, '.networks'),
283+
'KafkaDsn': (__spec__.parent, '.networks'),
284+
'NatsDsn': (__spec__.parent, '.networks'),
285+
'MySQLDsn': (__spec__.parent, '.networks'),
286+
'MariaDBDsn': (__spec__.parent, '.networks'),
287+
'ClickHouseDsn': (__spec__.parent, '.networks'),
288+
'validate_email': (__spec__.parent, '.networks'),
289289
# root_model
290-
'RootModel': (__package__, '.root_model'),
290+
'RootModel': (__spec__.parent, '.root_model'),
291291
# types
292-
'Strict': (__package__, '.types'),
293-
'StrictStr': (__package__, '.types'),
294-
'conbytes': (__package__, '.types'),
295-
'conlist': (__package__, '.types'),
296-
'conset': (__package__, '.types'),
297-
'confrozenset': (__package__, '.types'),
298-
'constr': (__package__, '.types'),
299-
'StringConstraints': (__package__, '.types'),
300-
'ImportString': (__package__, '.types'),
301-
'conint': (__package__, '.types'),
302-
'PositiveInt': (__package__, '.types'),
303-
'NegativeInt': (__package__, '.types'),
304-
'NonNegativeInt': (__package__, '.types'),
305-
'NonPositiveInt': (__package__, '.types'),
306-
'confloat': (__package__, '.types'),
307-
'PositiveFloat': (__package__, '.types'),
308-
'NegativeFloat': (__package__, '.types'),
309-
'NonNegativeFloat': (__package__, '.types'),
310-
'NonPositiveFloat': (__package__, '.types'),
311-
'FiniteFloat': (__package__, '.types'),
312-
'condecimal': (__package__, '.types'),
313-
'condate': (__package__, '.types'),
314-
'UUID1': (__package__, '.types'),
315-
'UUID3': (__package__, '.types'),
316-
'UUID4': (__package__, '.types'),
317-
'UUID5': (__package__, '.types'),
318-
'FilePath': (__package__, '.types'),
319-
'DirectoryPath': (__package__, '.types'),
320-
'NewPath': (__package__, '.types'),
321-
'Json': (__package__, '.types'),
322-
'Secret': (__package__, '.types'),
323-
'SecretStr': (__package__, '.types'),
324-
'SecretBytes': (__package__, '.types'),
325-
'StrictBool': (__package__, '.types'),
326-
'StrictBytes': (__package__, '.types'),
327-
'StrictInt': (__package__, '.types'),
328-
'StrictFloat': (__package__, '.types'),
329-
'PaymentCardNumber': (__package__, '.types'),
330-
'ByteSize': (__package__, '.types'),
331-
'PastDate': (__package__, '.types'),
332-
'FutureDate': (__package__, '.types'),
333-
'PastDatetime': (__package__, '.types'),
334-
'FutureDatetime': (__package__, '.types'),
335-
'AwareDatetime': (__package__, '.types'),
336-
'NaiveDatetime': (__package__, '.types'),
337-
'AllowInfNan': (__package__, '.types'),
338-
'EncoderProtocol': (__package__, '.types'),
339-
'EncodedBytes': (__package__, '.types'),
340-
'EncodedStr': (__package__, '.types'),
341-
'Base64Encoder': (__package__, '.types'),
342-
'Base64Bytes': (__package__, '.types'),
343-
'Base64Str': (__package__, '.types'),
344-
'Base64UrlBytes': (__package__, '.types'),
345-
'Base64UrlStr': (__package__, '.types'),
346-
'GetPydanticSchema': (__package__, '.types'),
347-
'Tag': (__package__, '.types'),
348-
'Discriminator': (__package__, '.types'),
349-
'JsonValue': (__package__, '.types'),
350-
'OnErrorOmit': (__package__, '.types'),
292+
'Strict': (__spec__.parent, '.types'),
293+
'StrictStr': (__spec__.parent, '.types'),
294+
'conbytes': (__spec__.parent, '.types'),
295+
'conlist': (__spec__.parent, '.types'),
296+
'conset': (__spec__.parent, '.types'),
297+
'confrozenset': (__spec__.parent, '.types'),
298+
'constr': (__spec__.parent, '.types'),
299+
'StringConstraints': (__spec__.parent, '.types'),
300+
'ImportString': (__spec__.parent, '.types'),
301+
'conint': (__spec__.parent, '.types'),
302+
'PositiveInt': (__spec__.parent, '.types'),
303+
'NegativeInt': (__spec__.parent, '.types'),
304+
'NonNegativeInt': (__spec__.parent, '.types'),
305+
'NonPositiveInt': (__spec__.parent, '.types'),
306+
'confloat': (__spec__.parent, '.types'),
307+
'PositiveFloat': (__spec__.parent, '.types'),
308+
'NegativeFloat': (__spec__.parent, '.types'),
309+
'NonNegativeFloat': (__spec__.parent, '.types'),
310+
'NonPositiveFloat': (__spec__.parent, '.types'),
311+
'FiniteFloat': (__spec__.parent, '.types'),
312+
'condecimal': (__spec__.parent, '.types'),
313+
'condate': (__spec__.parent, '.types'),
314+
'UUID1': (__spec__.parent, '.types'),
315+
'UUID3': (__spec__.parent, '.types'),
316+
'UUID4': (__spec__.parent, '.types'),
317+
'UUID5': (__spec__.parent, '.types'),
318+
'FilePath': (__spec__.parent, '.types'),
319+
'DirectoryPath': (__spec__.parent, '.types'),
320+
'NewPath': (__spec__.parent, '.types'),
321+
'Json': (__spec__.parent, '.types'),
322+
'Secret': (__spec__.parent, '.types'),
323+
'SecretStr': (__spec__.parent, '.types'),
324+
'SecretBytes': (__spec__.parent, '.types'),
325+
'StrictBool': (__spec__.parent, '.types'),
326+
'StrictBytes': (__spec__.parent, '.types'),
327+
'StrictInt': (__spec__.parent, '.types'),
328+
'StrictFloat': (__spec__.parent, '.types'),
329+
'PaymentCardNumber': (__spec__.parent, '.types'),
330+
'ByteSize': (__spec__.parent, '.types'),
331+
'PastDate': (__spec__.parent, '.types'),
332+
'FutureDate': (__spec__.parent, '.types'),
333+
'PastDatetime': (__spec__.parent, '.types'),
334+
'FutureDatetime': (__spec__.parent, '.types'),
335+
'AwareDatetime': (__spec__.parent, '.types'),
336+
'NaiveDatetime': (__spec__.parent, '.types'),
337+
'AllowInfNan': (__spec__.parent, '.types'),
338+
'EncoderProtocol': (__spec__.parent, '.types'),
339+
'EncodedBytes': (__spec__.parent, '.types'),
340+
'EncodedStr': (__spec__.parent, '.types'),
341+
'Base64Encoder': (__spec__.parent, '.types'),
342+
'Base64Bytes': (__spec__.parent, '.types'),
343+
'Base64Str': (__spec__.parent, '.types'),
344+
'Base64UrlBytes': (__spec__.parent, '.types'),
345+
'Base64UrlStr': (__spec__.parent, '.types'),
346+
'GetPydanticSchema': (__spec__.parent, '.types'),
347+
'Tag': (__spec__.parent, '.types'),
348+
'Discriminator': (__spec__.parent, '.types'),
349+
'JsonValue': (__spec__.parent, '.types'),
350+
'OnErrorOmit': (__spec__.parent, '.types'),
351351
# type_adapter
352-
'TypeAdapter': (__package__, '.type_adapter'),
352+
'TypeAdapter': (__spec__.parent, '.type_adapter'),
353353
# warnings
354-
'PydanticDeprecatedSince20': (__package__, '.warnings'),
355-
'PydanticDeprecatedSince26': (__package__, '.warnings'),
356-
'PydanticDeprecationWarning': (__package__, '.warnings'),
354+
'PydanticDeprecatedSince20': (__spec__.parent, '.warnings'),
355+
'PydanticDeprecatedSince26': (__spec__.parent, '.warnings'),
356+
'PydanticDeprecationWarning': (__spec__.parent, '.warnings'),
357357
# annotated handlers
358-
'GetCoreSchemaHandler': (__package__, '.annotated_handlers'),
359-
'GetJsonSchemaHandler': (__package__, '.annotated_handlers'),
358+
'GetCoreSchemaHandler': (__spec__.parent, '.annotated_handlers'),
359+
'GetJsonSchemaHandler': (__spec__.parent, '.annotated_handlers'),
360360
# generate schema from ._internal
361-
'GenerateSchema': (__package__, '._internal._generate_schema'),
361+
'GenerateSchema': (__spec__.parent, '._internal._generate_schema'),
362362
# pydantic_core stuff
363363
'ValidationError': ('pydantic_core', '.'),
364364
'ValidationInfo': ('pydantic_core', '.core_schema'),
@@ -367,13 +367,13 @@
367367
'FieldSerializationInfo': ('pydantic_core', '.core_schema'),
368368
'SerializerFunctionWrapHandler': ('pydantic_core', '.core_schema'),
369369
# deprecated, mostly not included in __all__
370-
'root_validator': (__package__, '.deprecated.class_validators'),
371-
'validator': (__package__, '.deprecated.class_validators'),
372-
'BaseConfig': (__package__, '.deprecated.config'),
373-
'Extra': (__package__, '.deprecated.config'),
374-
'parse_obj_as': (__package__, '.deprecated.tools'),
375-
'schema_of': (__package__, '.deprecated.tools'),
376-
'schema_json_of': (__package__, '.deprecated.tools'),
370+
'root_validator': (__spec__.parent, '.deprecated.class_validators'),
371+
'validator': (__spec__.parent, '.deprecated.class_validators'),
372+
'BaseConfig': (__spec__.parent, '.deprecated.config'),
373+
'Extra': (__spec__.parent, '.deprecated.config'),
374+
'parse_obj_as': (__spec__.parent, '.deprecated.tools'),
375+
'schema_of': (__spec__.parent, '.deprecated.tools'),
376+
'schema_json_of': (__spec__.parent, '.deprecated.tools'),
377377
'FieldValidationInfo': ('pydantic_core', '.core_schema'),
378378
}
379379

pydantic/_internal/_generate_schema.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,15 +1656,20 @@ def _unsubstituted_typevar_schema(self, typevar: typing.TypeVar) -> core_schema.
16561656

16571657
bound = typevar.__bound__
16581658
constraints = typevar.__constraints__
1659-
default = getattr(typevar, '__default__', None)
16601659

1661-
if (bound is not None) + (len(constraints) != 0) + (default is not None) > 1:
1660+
try:
1661+
typevar_has_default = typevar.has_default() # type: ignore
1662+
except AttributeError:
1663+
# could still have a default if it's an old version of typing_extensions.TypeVar
1664+
typevar_has_default = getattr(typevar, '__default__', None) is not None
1665+
1666+
if (bound is not None) + (len(constraints) != 0) + typevar_has_default > 1:
16621667
raise NotImplementedError(
16631668
'Pydantic does not support mixing more than one of TypeVar bounds, constraints and defaults'
16641669
)
16651670

1666-
if default is not None:
1667-
return self.generate_schema(default)
1671+
if typevar_has_default:
1672+
return self.generate_schema(typevar.__default__) # type: ignore
16681673
elif constraints:
16691674
return self._union_schema(typing.Union[constraints]) # type: ignore
16701675
elif bound:

pydantic/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
__all__ = 'VERSION', 'version_info'
55

6-
VERSION = '2.7.1'
6+
VERSION = '2.7.2'
77
"""The version of Pydantic."""
88

99

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ requires-python = '>=3.8'
4848
dependencies = [
4949
'typing-extensions>=4.6.1',
5050
'annotated-types>=0.4.0',
51-
"pydantic-core==2.18.2",
51+
"pydantic-core==2.18.3",
5252
]
5353
dynamic = ['version', 'readme']
5454

0 commit comments

Comments
 (0)