Can not load pydantic types when call CLI
elephantoid opened this issue Β· comments
π Bug report
currently I update pydantic
from v2.4.2 to v2.5.2.
and when using CLI from jsonargparse i got a error
----> 8 from jsonargparse import CLI
File ~/.conda/envs/bionlab/lib/python3.9/site-packages/jsonargparse/__init__.py:12
1 from argparse import (
2 ONE_OR_MORE,
3 OPTIONAL,
(...)
8 ArgumentError,
9 )
11 from ._actions import * # noqa: F403
---> 12 from ._cli import * # noqa: F403
13 from ._core import * # noqa: F403
14 from ._deprecated import * # noqa: F403
File ~/.conda/envs/bionlab/lib/python3.9/site-packages/jsonargparse/_cli.py:7
4 from typing import Any, Callable, Dict, List, Optional, Type, Union
6 from ._actions import ActionConfigFile, _ActionPrintConfig, remove_actions
----> 7 from ._core import ArgumentParser
8 from ._deprecated import deprecation_warning_cli_return_parser
9 from ._optionals import get_doc_short_description
File ~/.conda/envs/bionlab/lib/python3.9/site-packages/jsonargparse/_core.py:43
41 from ._common import is_dataclass_like, is_subclass, lenient_check, parser_context
42 from ._deprecated import ParserDeprecations
---> 43 from ._formatters import DefaultHelpFormatter, empty_help, get_env_var
44 from ._jsonnet import ActionJsonnet, ActionJsonnetExtVars
45 from ._jsonschema import ActionJsonSchema
File ~/.conda/envs/bionlab/lib/python3.9/site-packages/jsonargparse/_formatters.py:31
29 from ._optionals import import_ruyaml
30 from ._type_checking import ArgumentParser, ruyamlCommentedMap
---> 31 from ._typehints import ActionTypeHint, type_to_str
33 __all__ = ["DefaultHelpFormatter"]
36 empty_help: str = "_EMPTY_HELP_"
File ~/.conda/envs/bionlab/lib/python3.9/site-packages/jsonargparse/_typehints.py:74
53 from ._optionals import (
54 argcomplete_warn_redraw_prompt,
55 get_files_completer,
56 typing_extensions_import,
57 )
58 from ._util import (
59 ClassType,
60 NestedArg,
(...)
72 warning,
73 )
---> 74 from .typing import get_registered_type, is_pydantic_type
76 __all__ = ["lazy_instance"]
79 Literal = False if sys.version_info[:2] == (3, 6) else typing_extensions_import("Literal")
File ~/.conda/envs/bionlab/lib/python3.9/site-packages/jsonargparse/typing.py:448
445 if pydantic_support:
446 import pydantic
--> 448 for module in [pydantic.types, pydantic.networks]:
449 pydantic_types += tuple(
450 v for k, v in vars(module).items() if inspect.isclass(v) and k in module.__all__ and not issubclass(v, Enum)
451 )
454 def pydantic_deserializer(type_class):
File ~/.conda/envs/bionlab/lib/python3.9/site-packages/pydantic/__init__.py:363, in __getattr__(attr_name)
361 dynamic_attr = _dynamic_imports.get(attr_name)
362 if dynamic_attr is None:
--> 363 return _getattr_migration(attr_name)
365 package, module_name = dynamic_attr
367 from importlib import import_module
File ~/.conda/envs/bionlab/lib/python3.9/site-packages/pydantic/_migration.py:306, in getattr_migration.<locals>.wrapper(name)
304 if name in globals:
305 return globals[name]
--> 306 raise AttributeError(f'module {module!r} has no attribute {name!r}')
but i checked 2.5.2 pydantic. still there is a types.py
https://github.com/pydantic/pydantic/blob/v2.5.2/pydantic/types.py
Is there something what i miss?
To reproduce
jsonargparse 4.23.1
pydantic 2.5.2
from jsonargparse import CLI
Expected behavior
Environment
- jsonargparse version (4.23.1):
- Python version (3.9):
- How jsonargparse was installed (e.g.
pip install jsonargparse[signatures]>=4.17.0
): - OS (Linux):
Is there something what i miss?
@elephantoid any reason why you are using an old version of jsonargparse? If there is no reason, please update to the latest version.
The unit test were run yesterday with pydantic 2.5.2, so I doubt there is a bug. See https://app.circleci.com/pipelines/github/omni-us/jsonargparse/1544/workflows/8f18309f-7759-4194-8386-499c34583192/jobs/10870
Closing this since there hasn't been any response.