Coverage for /usr/local/lib/python3.12/site-packages/prefect/_internal/pydantic/v1_schema.py: 69%
35 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 10:48 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 10:48 +0000
1import inspect 1a
2import sys 1a
3import typing 1a
4import warnings 1a
6import pydantic 1a
9def is_v1_model(v: typing.Any) -> bool: 1a
10 with warnings.catch_warnings(): 1a
11 warnings.filterwarnings( 1a
12 "ignore", category=pydantic.warnings.PydanticDeprecatedSince20
13 )
15 if sys.version_info >= (3, 14): # Pydantic v1 is not supported in Python 3.14+ 15 ↛ 16line 15 didn't jump to line 16 because the condition on line 15 was never true1a
16 return False
18 from pydantic.v1 import BaseModel as V1BaseModel 1a
20 if isinstance(v, V1BaseModel): 20 ↛ 21line 20 didn't jump to line 21 because the condition on line 20 was never true1a
21 return True
22 try: 1a
23 if inspect.isclass(v) and issubclass(v, V1BaseModel): 23 ↛ 24line 23 didn't jump to line 24 because the condition on line 23 was never true1a
24 return True
25 except TypeError:
26 pass
28 return False 1a
31def is_v1_type(v: typing.Any) -> bool: 1a
32 if is_v1_model(v): 32 ↛ 33line 32 didn't jump to line 33 because the condition on line 32 was never true1a
33 return True
35 try: 1a
36 return v.__module__.startswith("pydantic.v1.types") 1a
37 except AttributeError:
38 return False
41def has_v1_type_as_param(signature: inspect.Signature) -> bool: 1a
42 parameters = signature.parameters.values() 1a
43 for p in parameters: 1a
44 # check if this parameter is a v1 model
45 if is_v1_type(p.annotation): 45 ↛ 46line 45 didn't jump to line 46 because the condition on line 45 was never true1a
46 return True
48 # check if this parameter is a collection of types
49 for v in typing.get_args(p.annotation): 1a
50 if is_v1_type(v): 50 ↛ 51line 50 didn't jump to line 51 because the condition on line 50 was never true1a
51 return True
52 return False 1a