Skip to content

Commit b73d420

Browse files
committed
update pydantic to 1.8.2
1 parent be665bb commit b73d420

File tree

9 files changed

+56
-40
lines changed

9 files changed

+56
-40
lines changed

robotcode/external/pydantic/pydantic/_hypothesis_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def add_luhn_digit(card_number: str) -> str:
149149
st.register_type_strategy(pydantic.SecretStr, st.text().map(pydantic.SecretStr))
150150

151151
# IP addresses, networks, and interfaces
152-
st.register_type_strategy(pydantic.IPvAnyAddress, st.ip_addresses())
152+
st.register_type_strategy(pydantic.IPvAnyAddress, st.ip_addresses()) # type: ignore[arg-type]
153153
st.register_type_strategy(
154154
pydantic.IPvAnyInterface,
155155
st.from_type(ipaddress.IPv4Interface) | st.from_type(ipaddress.IPv6Interface), # type: ignore[arg-type]

robotcode/external/pydantic/pydantic/datetime_parse.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
# if greater than this, the number is in ms, if less than or equal it's in seconds
5959
# (in seconds this is 11th October 2603, in ms it's 20th August 1970)
6060
MS_WATERSHED = int(2e10)
61+
# slightly more than datetime.max in ns - (datetime.max - EPOCH).total_seconds() * 1e9
62+
MAX_NUMBER = int(3e20)
6163
StrBytesIntFloat = Union[str, bytes, int, float]
6264

6365

@@ -73,6 +75,11 @@ def get_numeric(value: StrBytesIntFloat, native_expected_type: str) -> Union[Non
7375

7476

7577
def from_unix_seconds(seconds: Union[int, float]) -> datetime:
78+
if seconds > MAX_NUMBER:
79+
return datetime.max
80+
elif seconds < -MAX_NUMBER:
81+
return datetime.min
82+
7683
while abs(seconds) > MS_WATERSHED:
7784
seconds /= 1000
7885
dt = EPOCH + timedelta(seconds=seconds)

robotcode/external/pydantic/pydantic/decorator.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
11
from functools import wraps
2-
from typing import (
3-
TYPE_CHECKING,
4-
Any,
5-
Callable,
6-
Dict,
7-
List,
8-
Mapping,
9-
Optional,
10-
Tuple,
11-
Type,
12-
TypeVar,
13-
Union,
14-
get_type_hints,
15-
overload,
16-
)
2+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Mapping, Optional, Tuple, Type, TypeVar, Union, overload
173

184
from . import validator
195
from .errors import ConfigError
206
from .main import BaseModel, Extra, create_model
7+
from .typing import get_all_type_hints
218
from .utils import to_camel
229

2310
__all__ = ('validate_arguments',)
@@ -87,17 +74,17 @@ def __init__(self, function: 'AnyCallableT', config: 'ConfigType'): # noqa C901
8774
self.v_args_name = 'args'
8875
self.v_kwargs_name = 'kwargs'
8976

90-
type_hints = get_type_hints(function)
77+
type_hints = get_all_type_hints(function)
9178
takes_args = False
9279
takes_kwargs = False
9380
fields: Dict[str, Tuple[Any, Any]] = {}
9481
for i, (name, p) in enumerate(parameters.items()):
95-
if p.annotation == p.empty:
82+
if p.annotation is p.empty:
9683
annotation = Any
9784
else:
9885
annotation = type_hints[name]
9986

100-
default = ... if p.default == p.empty else p.default
87+
default = ... if p.default is p.empty else p.default
10188
if p.kind == Parameter.POSITIONAL_ONLY:
10289
self.arg_mapping[i] = name
10390
fields[name] = annotation, default

robotcode/external/pydantic/pydantic/fields.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def update_from_config(self, from_config: Dict[str, Any]) -> None:
169169
setattr(self, attr_name, value)
170170

171171
def _validate(self) -> None:
172-
if self.default not in (Undefined, Ellipsis) and self.default_factory is not None:
172+
if self.default is not Undefined and self.default_factory is not None:
173173
raise ValueError('cannot specify both default and default_factory')
174174

175175

@@ -370,9 +370,10 @@ def _get_field_info(
370370
field_info = next(iter(field_infos), None)
371371
if field_info is not None:
372372
field_info.update_from_config(field_info_from_config)
373-
if field_info.default not in (Undefined, Ellipsis):
373+
if field_info.default is not Undefined:
374374
raise ValueError(f'`Field` default cannot be set in `Annotated` for {field_name!r}')
375-
if value not in (Undefined, Ellipsis):
375+
if value is not Undefined and value is not Required:
376+
# check also `Required` because of `validate_arguments` that sets `...` as default value
376377
field_info.default = value
377378

378379
if isinstance(value, FieldInfo):
@@ -450,7 +451,6 @@ def prepare(self) -> None:
450451
self._type_analysis()
451452
if self.required is Undefined:
452453
self.required = True
453-
self.field_info.default = Required
454454
if self.default is Undefined and self.default_factory is None:
455455
self.default = None
456456
self.populate_validators()

robotcode/external/pydantic/pydantic/generics.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
TypeVar,
1616
Union,
1717
cast,
18-
get_type_hints,
1918
)
2019

20+
from typing_extensions import Annotated
21+
2122
from .class_validators import gather_all_validators
2223
from .fields import DeferredType
2324
from .main import BaseModel, create_model
24-
from .typing import display_as_type, get_args, get_origin, typing_base
25+
from .typing import display_as_type, get_all_type_hints, get_args, get_origin, typing_base
2526
from .utils import all_identical, lenient_issubclass
2627

2728
_generic_types_cache: Dict[Tuple[Type[Any], Union[Any, Tuple[Any, ...]]], Type[BaseModel]] = {}
@@ -73,7 +74,7 @@ def __class_getitem__(cls: Type[GenericModelT], params: Union[Type[Any], Tuple[T
7374
model_name = cls.__concrete_name__(params)
7475
validators = gather_all_validators(cls)
7576

76-
type_hints = get_type_hints(cls).items()
77+
type_hints = get_all_type_hints(cls).items()
7778
instance_type_hints = {k: v for k, v in type_hints if get_origin(v) is not ClassVar}
7879

7980
fields = {k: (DeferredType(), cls.__fields__[k].field_info) for k in instance_type_hints if k in cls.__fields__}
@@ -159,6 +160,10 @@ def replace_types(type_: Any, type_map: Mapping[Any, Any]) -> Any:
159160
type_args = get_args(type_)
160161
origin_type = get_origin(type_)
161162

163+
if origin_type is Annotated:
164+
annotated_type, *annotations = type_args
165+
return Annotated[replace_types(annotated_type, type_map), tuple(annotations)]
166+
162167
# Having type args is a good indicator that this is a typing module
163168
# class instantiation or a generic alias of some sort.
164169
if type_args:
@@ -167,7 +172,12 @@ def replace_types(type_: Any, type_map: Mapping[Any, Any]) -> Any:
167172
# If all arguments are the same, there is no need to modify the
168173
# type or create a new object at all
169174
return type_
170-
if origin_type is not None and isinstance(type_, typing_base) and not isinstance(origin_type, typing_base):
175+
if (
176+
origin_type is not None
177+
and isinstance(type_, typing_base)
178+
and not isinstance(origin_type, typing_base)
179+
and getattr(type_, '_name', None) is not None
180+
):
171181
# In python < 3.9 generic aliases don't exist so any of these like `list`,
172182
# `type` or `collections.abc.Callable` need to be translated.
173183
# See: https://www.python.org/dev/peps/pep-0585

robotcode/external/pydantic/pydantic/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def inherit_config(self_config: 'ConfigType', parent_config: 'ConfigType', **nam
184184
namespace['json_encoders'] = {
185185
**getattr(parent_config, 'json_encoders', {}),
186186
**getattr(self_config, 'json_encoders', {}),
187+
**namespace.get('json_encoders', {}),
187188
}
188189

189190
return type('Config', base_classes, namespace)
@@ -248,7 +249,12 @@ def __new__(mcs, name, bases, namespace, **kwargs): # noqa C901
248249
class_vars.update(base.__class_vars__)
249250
hash_func = base.__hash__
250251

251-
config_kwargs = {key: kwargs.pop(key) for key in kwargs.keys() & BaseConfig.__dict__.keys()}
252+
allowed_config_kwargs: SetStr = {
253+
key
254+
for key in dir(config)
255+
if not (key.startswith('__') and key.endswith('__')) # skip dunder methods and attributes
256+
}
257+
config_kwargs = {key: kwargs.pop(key) for key in kwargs.keys() & allowed_config_kwargs}
252258
config_from_namespace = namespace.get('Config')
253259
if config_kwargs and config_from_namespace:
254260
raise TypeError('Specifying config in two places is ambiguous, use either Config attribute or class kwargs')

robotcode/external/pydantic/pydantic/schema.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ def field_singleton_schema( # noqa: C901 (ignore complexity)
788788
f_schema: Dict[str, Any] = {}
789789
if field.field_info is not None and field.field_info.const:
790790
f_schema['const'] = field.default
791+
791792
field_type = field.type_
792793
if is_literal_type(field_type):
793794
values = all_literal_values(field_type)
@@ -805,8 +806,8 @@ def field_singleton_schema( # noqa: C901 (ignore complexity)
805806
# All values have the same type
806807
field_type = values[0].__class__
807808
f_schema['enum'] = list(values)
808-
809-
if lenient_issubclass(field_type, Enum):
809+
add_field_type_to_schema(field_type, f_schema)
810+
elif lenient_issubclass(field_type, Enum):
810811
enum_name = model_name_map[field_type]
811812
f_schema, schema_overrides = get_field_info_schema(field)
812813
f_schema.update(get_schema_ref(enum_name, ref_prefix, ref_template, schema_overrides))

robotcode/external/pydantic/pydantic/typing.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sys
2-
from enum import Enum
32
from typing import ( # type: ignore
43
TYPE_CHECKING,
54
AbstractSet,
@@ -18,6 +17,7 @@
1817
Union,
1918
_eval_type,
2019
cast,
20+
get_type_hints,
2121
)
2222

2323
from typing_extensions import Annotated, Literal
@@ -70,6 +70,18 @@ def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any:
7070
return cast(Any, type_)._evaluate(globalns, localns, set())
7171

7272

73+
if sys.version_info < (3, 9):
74+
# Ensure we always get all the whole `Annotated` hint, not just the annotated type.
75+
# For 3.6 to 3.8, `get_type_hints` doesn't recognize `typing_extensions.Annotated`,
76+
# so it already returns the full annotation
77+
get_all_type_hints = get_type_hints
78+
79+
else:
80+
81+
def get_all_type_hints(obj: Any, globalns: Any = None, localns: Any = None) -> Any:
82+
return get_type_hints(obj, globalns, localns, include_extras=True)
83+
84+
7385
if sys.version_info < (3, 7):
7486
from typing import Callable as Callable
7587

@@ -225,6 +237,7 @@ def get_args(tp: Type[Any]) -> Tuple[Any, ...]:
225237
'get_args',
226238
'get_origin',
227239
'typing_base',
240+
'get_all_type_hints',
228241
)
229242

230243

@@ -236,14 +249,6 @@ def display_as_type(v: Type[Any]) -> str:
236249
if not isinstance(v, typing_base) and not isinstance(v, GenericAlias) and not isinstance(v, type):
237250
v = v.__class__
238251

239-
if isinstance(v, type) and issubclass(v, Enum):
240-
if issubclass(v, int):
241-
return 'int'
242-
elif issubclass(v, str):
243-
return 'str'
244-
else:
245-
return 'enum'
246-
247252
if isinstance(v, GenericAlias):
248253
# Generic alias are constructs like `list[int]`
249254
return str(v).replace('typing.', '')

robotcode/external/pydantic/pydantic/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__all__ = 'VERSION', 'version_info'
22

3-
VERSION = '1.8.1'
3+
VERSION = '1.8.2'
44

55

66
def version_info() -> str:

0 commit comments

Comments
 (0)