Pydantic: Pylint complains about "No name 'SecretStr' in module 'pydantic'"

Created on 13 Nov 2019  路  11Comments  路  Source: samuelcolvin/pydantic

Bug

Pylint complains about missing pydantic data types but they can be used without problems.

I see this problem inside this Docker image: tiangolo/uvicorn-gunicorn-fastapi:python3.7. It does not occur in my dev environment under MacOS.

Please complete:

  • OS: Linux
  • Python version import sys; print(sys.version): *3.7.4
  • Pydantic version import pydantic; print(pydantic.VERSION): 0.32.2

Where possible please include a self contained code snippet describing your bug

Put this content into app.py:

"""app.py"""
from pydantic import SecretStr

SECRET = SecretStr('ab')

Then install pylint with pip install pylint and run pylint app.py

bug

Most helpful comment

--extension-pkg-whitelist=pydantic solves this.

All 11 comments

Seems to work fine for me with v0.32.2, v1, v1.1 and master.

You'll have to provide more details, however in general I'll only be fixing critical and security bugs in v0.32.

I would like to re-open (but I cannot) as I can reproduce this with the python:3.7 Docker image and pydantic 1.1 like this:

  • Create app.py in the current directory like described above
  • Run docker run --rm -v $(pwd):/app -it python:3.7 /bin/bash
  • Run pip install pydantic==1.1 pylint
  • Run pylint app.py

See my error message above.

Looks like this is a problem with pylint if you instead install pydantic with pip install git+git://github.com/samuelcolvin/pydantic@master#egg=pydantic it works fine again.

Also see

https://github.com/samuelcolvin/pydantic/blob/677537d1f5e15c1d82fff537c9c6ca97e82702c1/pydantic/__init__.py#L11

and

https://github.com/samuelcolvin/pydantic/blob/677537d1f5e15c1d82fff537c9c6ca97e82702c1/pydantic/types.py#L62

and

https://github.com/samuelcolvin/pydantic/blob/677537d1f5e15c1d82fff537c9c6ca97e82702c1/pydantic/types.py#L461

The export is arranged correctly, at least I wouldn't know what's wrong with it.

I can confirm that it does not occur when installing pydantic directly from git in the Docker container. So now I am comparing the versions that are getting installed:

Docker:

Collecting pydantic==1.1
  Using cached https://files.pythonhosted.org/packages/f9/20/38e48f037c1d30851ef5a280d4c17ce027bae4310f27ad51fff1fe0a7cb0/pydantic-1.1-cp37-cp37m-manylinux1_x86_64.whl

MacOS:

Collecting pydantic==1.1
  Downloading https://files.pythonhosted.org/packages/58/85/e39bc2e8cd19625ec3514521e2e3f5e6e104113badc9c25e79a30329df6b/pydantic-1.1-py36.py37.py38-none-any.whl (80kB)

Does this cp37-cp37m-manylinux1 mean something to you and could it influence pylint somehow?

Yes, it means it's compiled with cython.

But I also tried installing from git but compiling (just run pip install cython before installing pydantic) and I didn't get the error, so I assume it's not directly related to compilation, but I could be wrong.

See #555

see https://pydantic-docs.helpmanual.io/install/ for details on cython compiling.

I can confirm that cython is the culprit on Mac OS and in the python:3.7 Docker image I mentioned earlier. However, this is my first encounter with cython and I have no idea what/where to look for in that realm.

Works:

pipenv install --python python3
pipenv shell
pip install pylint
pip install git+http://github.com/samuelcolvin/pydantic@master#egg=pydantic

pipenv run pylint app.py

Gives the error message (see above):

pipenv install --python python3
pipenv shell
pip install cython
pip install pylint
pip install git+http://github.com/samuelcolvin/pydantic@master#egg=pydantic

pipenv run pylint app.py

maybe ask on pylint then.

Fine. Here is a first reference: https://github.com/PyCQA/pylint/issues/2799

--extension-pkg-whitelist=pydantic solves this.

Just for the sake of completeness, here is the explanation to why this option is required: http://pylint.pycqa.org/en/latest/technical_reference/c_extensions.html

Was this page helpful?
0 / 5 - 0 ratings