Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mypy false positive: metaclass conflict #96

Closed
ofacklam opened this issue Jun 4, 2024 · 2 comments · Fixed by #97
Closed

Mypy false positive: metaclass conflict #96

ofacklam opened this issue Jun 4, 2024 · 2 comments · Fixed by #97
Labels
bug Something isn't working

Comments

@ofacklam
Copy link

ofacklam commented Jun 4, 2024

Mypy detects a metaclass conflict as soon as we subclass the ConfZ class as per default use case:

reproduce.py:

from confz import ConfZ, ConfZEnvSource


class MyConfig(ConfZ):
    my_config_variable: bool

    CONFIG_SOURCES = [ConfZEnvSource(allow_all=True)]

Output of mypy:

❯ mypy .
reproduce.py:4: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
Found 1 error in 1 file (checked 1 source file)

Used configuration:

❯ python3 --version
Python 3.10.12
❯ pip3 list
Package           Version
----------------- -------
confz             1.7.0
mypy              1.10.0
mypy-extensions   1.0.0
pip               22.0.2
pydantic          1.10.15
python-dotenv     0.21.1
PyYAML            6.0.1
setuptools        59.6.0
toml              0.10.2
tomli             2.0.1
typing_extensions 4.12.1

Note: It seems to still be the case with confZ 2 when using BaseConfig

@silvanmelchior silvanmelchior added the bug Something isn't working label Jun 11, 2024
@silvanmelchior silvanmelchior linked a pull request Jun 11, 2024 that will close this issue
@silvanmelchior
Copy link
Collaborator

Indeed, seams to be a limitation of MyPy, it doesn't correctly recognize the metaclass because pydantic's Metaclass does not inherit from type (https://mypy.readthedocs.io/en/stable/metaclasses.html, last point).

Thanks for pointing it out, I will adjust the docs.

Interestingly, this problem did not exist with older versions of MyPy (tried it with 0.940, there it still accepts it).

@silvanmelchior
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants