Hi all. Okay, I’m confused. I’m trying to address ...
# general
c
Hi all. Okay, I’m confused. I’m trying to address or eliminate this error
No name 'BaseModel' in module 'pydantic' (no-name-in-module)
from pylint in my project, but I’m having no luck. No change to my pyproject.toml or pants.toml or .pylintrc file seems to make any difference. Got any suggestions where to look? To be honest I’m not sure pylint is using my .pylintrc file… 😞
p
I am not familiar w/ pydantic, but I think it is useful to add relevant plugins to pylint so it better understand different frameworks. We add pylint-django, you might want to add https://github.com/fcfangcc/pylint-pydantic to the pylint plugins. This is done via the
[pylint].extra_requirements
option.
ours looks something like that:
Screen Shot 2022-11-04 at 4.54.11 PM.png
you need to tell pants about the pylintrc file, via the config option. https://www.pantsbuild.org/docs/reference-pylint#config
w
also, independently of any particularly linter, you’ll want to ensure that
./pants dependencies $file_in_question
actually shows
pydantic
(matching your
import
statement)… if it doesn’t, then Pants won’t know to put it in the sandbox
c
@polite-garden-50641 Again, maybe I’m being dense, but I’ve tried a few iterations of doing what you suggest, and always get an error. This what I just tried in my pants.toml file:
Copy code
[pylint]
PANTS_PYLINT_CONFIG = "config/.pylintrc"
When I run
./pants lint ::
I get this:
Copy code
17:17:07.90 [INFO] Initializing scheduler...
17:17:08.06 [INFO] Scheduler initialized.
17:17:08.08 [ERROR] Invalid option 'PANTS_PYLINT_CONFIG' under [pylint] in /Users/dfarrell/projects/rh/recurring-payment/pants.toml
17:17:08.08 [ERROR] Invalid config entries detected. See log for details on which entries to update or remove.
(Specify --no-verify-config to disable this check.)
@witty-crayon-22786 I ran the line you’re suggesting, I see fastapi being reported as a dependency, which I think has a dependency on pydantic. Do I need to do something explicit to add pydantic?
Sorry, will have to wait till Monday, have to pick up or dog. 🙂
w
Do I need to do something explicit to add pydantic?
if you have an explicit
import
of pydantic, then yes… if you do not have an explicit
import
of pydantic, and it is instead a transitive dependency, then no: it should be added to the sandbox for
pylint
automatically, because
pylint
uses the transitive dependencies of your code
1
h
PANTS_PYLINT_CONFIG
is how you would set that option as an env var. You want
Copy code
[pylint]
config = "config/.pylintrc"
1
c
Sigh, I’m still so confused. I added:
Copy code
[pylint]
config = "config/.pylintrc"
To my `pants.toml file, and it seems to be reading the file, but I’m still getting
Copy code
R0903: Too few public methods (0/2) (too-few-public-methods)
errors from my files even though I have
Copy code
disable=too-few-public-methods
In my
.pylintrc
file. 😞
Just tried
Copy code
disable=R0903
instead of using the name, that works! Are the names (too-few-public-methods) broken in some way?
h
I doubt Pants is doing anything to break them, or at least not purposely, maybe the pylint version being used doesn’t support disabling by name?
Pants doesn’t parse or otherwise tinker with .pylintrc AFAIK
Hmm, curious. Pants uses pylint 2.13.9 by default, and that version should support disabling by name: https://pylint.pycqa.org/en/v2.13.9/user_guide/message-control.html
See what happens if you use this directly in that version of pylint I guess?
c
@happy-kitchen-89482 I’ll give that a try, thanks for your continued help with my issues. 🙂