Pydantic: mypy `from pydantic import BaseModel`

Created on 10 Feb 2020  路  8Comments  路  Source: samuelcolvin/pydantic

Mypy fails on this for me as well:

pydantic version: 1.3
pydantic compiled: True
install path: /usr/local/lib/python3.7/site-packages/pydantic
python version: 3.7.4 (default, Sep 12 2019, 15:40:15)  [GCC 8.3.0]
platform: Linux-4.19.76-linuxkit-x86_64-with-debian-10.1
optional deps. installed: ['typing-extensions', 'email-validator']
from pydantic import BaseModel as PydanticBaseModel


class BaseModel(PydanticBaseModel):
    class Config:
        allow_mutation = False
        case_sensitive = True
        use_enum_values = True
        anystr_strip_whitespace = True
[mypy]
python_version = 3.7
mypy_path = ./src
show_error_codes = True
plugins = pydantic.mypy

follow_imports = normal
strict_optional = True
warn_redundant_casts = True
warn_unused_ignores = True
disallow_any_generics = True
check_untyped_defs = True
no_implicit_reexport = True

# for strict mypy: (this is the tricky one :-))
; disallow_untyped_defs = True

[pydantic-mypy]
init_forbid_extra = True
init_typed = True
warn_required_dynamic_aliases = True
warn_untyped_fields = True

mypy --config-file mypy.ini ./src

Outputs:

src/base_model.py:2: error: Module 'pydantic' has no attribute 'BaseModel' [attr-defined]

https://github.com/samuelcolvin/pydantic/issues/1072

bug

Most helpful comment

@ronaldevers I ended up doing: extension-pkg-whitelist=pydantic inside my .pylintrc

All 8 comments

this was fixed in pydantic 1.4

Hi @samuelcolvin, I'm seeing this issue with Python 3.8.1 / Pydantic 1.5.1 but with pylint 2.5.2. It does work on mypy. Any thoughts? Should I open a new issue?

$ pylint --version
pylint 2.5.2
astroid 2.4.1
Python 3.8.1 (default, Feb 25 2020, 17:22:31) 
[Clang 11.0.0 (clang-1100.0.33.17)]

$ cat test.py
from pydantic import BaseModel
print(BaseModel)

$ pylint test.py
************* Module test
test.py:1:0: C0114: Missing module docstring (missing-module-docstring)
test.py:1:0: E0611: No name 'BaseModel' in module 'pydantic' (no-name-in-module)
-------------------------------------
Your code has been rated at -20.00/10

If you're sure you're using v1.5.1, it had to be a problem with pylint:

https://github.com/samuelcolvin/pydantic/blob/master/pydantic/__init__.py

Maybe ask there.

Yeah it's 1.5.1, double and triple-checked. I reckon pylint isn't smart enough to pick up BaseModel from the * import then. If that's the problem I don't see them fixing that actually. Guess we have mypy for a reason then eh..

Humm, it's explicitly listed in __all__, but maybe.

@ronaldevers I ended up doing: extension-pkg-whitelist=pydantic inside my .pylintrc

Hey, did anyone found the solution? Same problem here.

I hooked up mypy instead of pylint. 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chopraaa picture chopraaa  路  18Comments

jasonkuhrt picture jasonkuhrt  路  19Comments

Yolley picture Yolley  路  18Comments

cazgp picture cazgp  路  34Comments

sm-Fifteen picture sm-Fifteen  路  45Comments