coltonbh / qcio

A package for structured Quantum Chemistry data.
MIT License
4 stars 2 forks source link

Pydantic error on import: "Pydantic does not support mixing more than one of TypeVar bounds, constraints and defaults" #54

Closed Contextualist closed 3 months ago

Contextualist commented 4 months ago

Steps to reproduce

Open a Python interpreter interactive session, then enter import qcio.

What I observed

Traceback: ```bash Traceback (most recent call last): File "", line 1, in File "/PATH/TO/lib/python3.12/site-packages/qcio/__init__.py", line 4, in from .models import * # noqa: F403 ^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/qcio/models/__init__.py", line 3, in from .outputs import * # noqa: F403 ^^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/qcio/models/outputs.py", line 294, in class ProgramOutput(QCIOModelBase, Generic[InputType, ResultsType]): File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 183, in __new__ complete_model_class( File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 517, in complete_model_class schema = cls.__get_pydantic_core_schema__(cls, handler) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/main.py", line 584, in __get_pydantic_core_schema__ return __handler(__source) ^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__ schema = self._handler(__source_type) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 490, in generate_schema schema = self._generate_schema(obj) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 721, in _generate_schema schema = self._generate_schema_inner(obj) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 742, in _generate_schema_inner return self._model_schema(obj) ^^^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 563, in _model_schema {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()}, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 906, in _generate_md_field_schema common_field = self._common_field_schema(name, field_info, decorators) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1071, in _common_field_schema schema = self._apply_annotations( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1765, in _apply_annotations schema = get_inner_schema(source_type) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__ schema = self._handler(__source_type) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1746, in inner_handler schema = self._generate_schema(obj) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 721, in _generate_schema schema = self._generate_schema_inner(obj) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 747, in _generate_schema_inner return self.match_type(obj) ^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 806, in match_type return self._unsubstituted_typevar_schema(obj) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/PATH/TO/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1610, in _unsubstituted_typevar_schema raise NotImplementedError( NotImplementedError: Pydantic does not support mixing more than one of TypeVar bounds, constraints and defaults ```

Environment

Python: 3.12.4

Excerpt from pip list:

qcio                      0.11.7
pydantic                  2.6.4
pydantic_core             2.16.3
pydantic-settings         2.2.1

Let me know if you need more information.

coltonbh commented 4 months ago

Thanks @Contextualist! Will check this out this week :)

coltonbh commented 3 months ago

Cannot reproduce!

python -m venv env
source ./env/bin/activate
pip install qcio
~/dev/hacking/qcio_hacking ❯ python                                                                                   qcio_hacking
Python 3.12.4 (main, Aug  5 2024, 14:31:57) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import qcio
>>> 
coltonbh commented 3 months ago
~/dev/hacking/qcio_hacking ❯ pip freeze                                                                          32s  qcio_hacking
annotated-types==0.7.0
numpy==1.26.4
pydantic==2.8.2
pydantic_core==2.20.1
PyYAML==6.0.1
qcio==0.11.7
toml==0.10.2
typing_extensions==4.12.2

Perhaps upgrade your pydantic version?

Contextualist commented 3 months ago

Thanks! The issue goes away after upgrading to pydantic 2.8.2 and pydantic_core 2.20.1

coltonbh commented 3 months ago

Excellent! Happy to hear it :)