Using types with Pydantic results in TypeError
Consider the following example, which a transscript of the same example from the docs using Pydantic instead of attrs:
import click
import typed_settings as ts
from pydantic import BaseModel
class Settings(BaseModel):
a: int | None
b: list[int] | None
@click.command()
@ts.click_options(Settings, "example")
def cli(settings: Settings):
print(settings)
if __name__ == "__main__":
cli()
Running the script fails with:
$ python test.py --help
Traceback (most recent call last):
File "[redacted]/test.py", line 18, in <module>
@ts.click_options(Settings, "example")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[redacted]/.venv/lib/python3.11/site-packages/typed_settings/cli_click.py", line 185, in click_options
grouped_options = cls_utils.group_options(state.settings_class, state.options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[redacted]/.venv/lib/python3.11/site-packages/typed_settings/cls_utils.py", line 402, in group_options
fields_to_parents = cls_handler.fields_to_parent_classes(cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[redacted]/.venv/lib/python3.11/site-packages/typed_settings/cls_utils.py", line 311, in fields_to_parent_classes
return {
^
File "[redacted]/.venv/lib/python3.11/site-packages/typed_settings/cls_utils.py", line 314, in <dictcomp>
if issubclass(field.annotation, pydantic.BaseModel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen abc>", line 123, in __subclasscheck__
TypeError: issubclass() arg 1 must be a class
The problem occurs when using types from the typing package, such as Union or Optional. I'm using:
typed-settings==24.1.0
pydantic==2.6.1
pydantic_core==2.16.2