NowanIlfideme / pydantic-yaml

YAML support for Pydantic models
MIT License
138 stars 11 forks source link

Mypy error #3

Closed Tonkonozhenko closed 3 years ago

Tonkonozhenko commented 3 years ago

Hi @NowanIlfideme

I'm trying to use the library with mypy and have next error. Please advice

$ mypy --config-file tox.ini config.py
config.py:3: error: Skipping analyzing 'pydantic_yaml': found module but no type hints or library stubs
config.py:3: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
config.py:9: error: Class cannot subclass 'YamlModel' (has type 'Any')

Regards, Alex

NowanIlfideme commented 3 years ago

Hi, I've had that error with external libraries as well. I'm not 100% sure what causes that.

Judging by a quick search, and this SO answer, it seems I need to add a py.typed file somewhere into the package to adhere to PEP 561.

I'm super busy this week, but to fix it you can try this for now:

from typing import Type
from pydantic import BaseModel
from pydantic_yaml import YamlModel # type: ignore

YamlModel: Type[BaseModel]

Obviously not ideal, but I expect this should work for now?

NowanIlfideme commented 3 years ago

Closed by PR #4 Opened #5 to add tests for this case at some point. :)

Tonkonozhenko commented 3 years ago

@NowanIlfideme unfortunately, needs to reopen. py.typed file is not included in the package I checked the installation via pip install -e "git+https://github.com/tonkonozhenko/pydantic-yaml.git@patch-1#egg=pydantic_yaml" and it worked correctly

NowanIlfideme commented 3 years ago

Please test this again, I believe I fixed it & some other issues that would've come up. But you have the real-life use case, so it would be a better test. 😉

Tonkonozhenko commented 3 years ago

@NowanIlfideme Now everything works. Thanks a lot!