jucacrispim / pylint-mongoengine Goto Github PK
View Code? Open in Web Editor NEWPylint plugin to handle mongoengine stuff
License: GNU General Public License v3.0
Pylint plugin to handle mongoengine stuff
License: GNU General Public License v3.0
Hello,
After installing the plugin, I'm getting R0903: Too few public methods (0/2) (too-few-public-methods)
for Document classes that only describe a schema, some as simple as
from mongoengine import Document
from mongoengine.fields import IntField, StringField
class MyModel(Document):
some_string_field = StringField(required=True)
some_int_field = IntField(required=True)
I do have min_public_methods=2
in my .pylintrc
, but without the plugin pylint knows not to warn about these classes. Any idea why?
Best regards.
I'm not sure if this is a pylint-mongoengine or pylint issue, but it happens only when I load pylint-mongoengine plugin.
When i run pylint --load-plugins=pylint_mongoengine server/
i get
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\dorin\AppData\Local\Programs\Python\Python38-32\Scripts\pylint.exe\__main__.py", line 7, in <module>
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\site-packages\pylint\__init__.py", line 22, in run_pylint
PylintRun(sys.argv[1:])
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\site-packages\pylint\lint\run.py", line 262, in __init__
linter.load_plugin_modules(self._plugins)
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\site-packages\pylint\lint\pylinter.py", line 490, in load_plugin_modules
module = modutils.load_module_from_name(modname)
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\site-packages\astroid\modutils.py", line 203, in load_module_from_name
return load_module_from_modpath(dotted_name.split("."), path, use_sys)
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\site-packages\astroid\modutils.py", line 245, in load_module_from_modpath
module = imp.load_module(curname, mp_file, mp_filename, mp_desc)
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\imp.py", line 244, in load_module
return load_package(name, filename)
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\imp.py", line 216, in load_package
return _load(spec)
File "<frozen importlib._bootstrap>", line 702, in _load
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\site-packages\pylint_mongoengine\__init__.py", line 19, in <module>
from pylint_mongoengine.checkers.mongoengine import MongoEngineChecker
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\site-packages\pylint_mongoengine\checkers\mongoengine.py", line 23, in <module>
from pylint_mongoengine.utils import (
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\site-packages\pylint_mongoengine\utils.py", line 6, in <module>
from mongoengine import Document
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\site-packages\mongoengine\__init__.py", line 5, in <module>
from mongoengine import fields
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\site-packages\mongoengine\fields.py", line 22, in <module>
import dateutil.parser
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\site-packages\dateutil\parser\__init__.py", line 2, in <module>
from ._parser import parse, parser, parserinfo, ParserError
File "c:\users\dorin\appdata\local\programs\python\python38-32\lib\site-packages\dateutil\parser\_parser.py", line 49, in <module>
from .. import relativedelta
ImportError: cannot import name 'relativedelta' from 'dateutil' (unknown location)
Version of packages i have installed:
Re-reporting from Pylint issue
"""
Mixed use of pydantic with mongoengine that raises
astroid.exceptions.InferenceError: StopIteration raised without any error information.
"""
from mongoengine import Document
from pydantic import BaseModel
class Users(Document): # pylint: disable=too-few-public-methods
"""A mongoengine document model"""
class UsersPydantic(BaseModel): # pylint: disable=too-few-public-methods
"""Pydantic Base Model"""
type_: Users
def get_value(self) -> Users:
"""get some document"""
return self.type_.objects()[0]
class Config: # pylint: disable=too-few-public-methods
"""update meta details"""
arbitrary_types_allowed = True
[MAIN]
extension-pkg-whitelist=pydantic, mongoengine
load-plugins=pylint_pydantic, pylint_mongoengine
pylint my_code.py
pylint crashed with a ``AstroidError`` and with the following stacktrace:
Traceback (most recent call last):
File "my_repo/virtuals/lib/python3.10/site-packages/astroid/decorators.py", line 140, in raise_if_nothing_inferred
yield next(generator)
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "my_repo/virtuals/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 790, in _lint_file
check_astroid_module(module)
File "my_repo/virtuals/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1060, in check_astroid_module
retval = self._check_astroid_module(
File "my_repo/virtuals/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1110, in _check_astroid_module
walker.walk(node)
File "my_repo/virtuals/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 93, in walk
self.walk(child)
File "my_repo/virtuals/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 93, in walk
self.walk(child)
File "my_repo/virtuals/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 93, in walk
self.walk(child)
[Previous line repeated 3 more times]
File "my_repo/virtuals/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 90, in walk
callback(astroid)
File "my_repo/virtuals/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 60, in __call__
self.augmentation_func(Chain(self.old_method, node), node)
File "my_repo/virtuals/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 117, in __call__
if self.test_func(node):
File "my_repo/virtuals/lib/python3.10/site-packages/pylint_mongoengine/utils.py", line 115, in node_is_default_qs
for cls in base_cls.inferred():
File "my_repo/virtuals/lib/python3.10/site-packages/astroid/nodes/node_ng.py", line 611, in inferred
return list(self.infer())
File "my_repo/virtuals/lib/python3.10/site-packages/astroid/nodes/node_ng.py", line 169, in infer
yield from self._infer(context=context, **kwargs)
File "my_repo/virtuals/lib/python3.10/site-packages/astroid/decorators.py", line 146, in raise_if_nothing_inferred
raise InferenceError(
astroid.exceptions.InferenceError: StopIteration raised without any error information.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "my_repo/virtuals/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 755, in _lint_files
self._lint_file(fileitem, module, check_astroid_module)
File "my_repo/virtuals/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 792, in _lint_file
raise astroid.AstroidError from e
astroid.exceptions.AstroidError
Pylint exits peacefully!
pylint 2.15.9
astroid 2.12.13
Python 3.10.8 (main, Oct 21 2022, 22:22:30) [Clang 14.0.0 (clang-1400.0.29.202)]
No response
pylint-mongoengine==0.4.0
pylint-plugin-utils==0.7
pylint-pydantic==0.1.4
pydantic==1.10.4
mongoengine==0.25.0
The new Pylint version 3 doesn't work with this plugin and it fails with an ImportError.
$ pylint my_project
Traceback (most recent call last):
File "/builds/private/my-project/.venv/bin/pylint", line 8, in <module>
sys.exit(run_pylint())
File "/builds/private/my-project/.venv/lib/python3.10/site-packages/pylint/__init__.py", line 34, in run_pylint
PylintRun(argv or sys.argv[1:])
File "/builds/private/my-project/.venv/lib/python3.10/site-packages/pylint/lint/run.py", line 162, in __init__
args = _config_initialization(
File "/builds/private/my-project/.venv/lib/python3.10/site-packages/pylint/config/config_initialization.py", line 61, in _config_initialization
linter.load_plugin_modules(utils._splitstrip(config_data["load-plugins"]))
File "/builds/private/my-project/.venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 380, in load_plugin_modules
module = astroid.modutils.load_module_from_name(modname)
File "/builds/private/my-project/.venv/lib/python3.10/site-packages/astroid/modutils.py", line 194, in load_module_from_name
module = importlib.import_module(dotted_name)
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/builds/private/my-project/.venv/lib/python3.10/site-packages/pylint_mongoengine/__init__.py", line 19, in <module>
from pylint_mongoengine.checkers.mongoengine import MongoEngineChecker
File "/builds/private/my-project/.venv/lib/python3.10/site-packages/pylint_mongoengine/checkers/mongoengine.py", line 20, in <module>
from pylint.checkers.utils import check_messages
ImportError: cannot import name 'check_messages' from 'pylint.checkers.utils' (/builds/private/my-project/.venv/lib/python3.10/site-packages/pylint/checkers/utils.py)
Calls to querysets are not being detected and therefore errors about missing and unexpected arguments are not being suppressed.
The problem is in suppression.py
, line 35; dec.name
should be dec.attrname
If you have a class which has an embedded document field, and that field is required, attempting to access a field from that subdocument will generate an error.
import mongoengine as _me
class Foo(_me.EmbeddedDocument):
my_field: str = _me.StringField()
class Bar(_me.Document):
my_embed: Foo = _me.EmbeddedDocumentField(Foo, required=True)
def my_method(self):
print(self.my_embed.my_field) # Error when linting this line
The issues seems to be due to the following code from utils.py, line 138:
cls_name = definition.last_child().last_child()
This assumes that the child document class of an EmbeddedDocumentField will always be its last child, which is true if the embedded class name is the only argument passed to the constructor, but not true if there are additional arguments.
Hello! I am very interested in this project, but struggling to find documentation? There is some?
Also, there is a roadmap for future development? Or is this a "dead" project?
It would be great if this plugin used pylint-plugin-utils
at version 0.5 or higher, due to this bug: pylint-dev/pylint-plugin-utils#12
When using pylint-mongoengine
with VSCode and the pylance
extension, I still get the following error:
import mongoengine
class Team(mongoengine.Document):
name = mongoengine.StringField()
location = mongoengine.StringField()
shorthand = mongoengine.StringField()
logo_src = mongoengine.URLField()
home_primary_color = mongoengine.StringField()
home_secondary_color = mongoengine.StringField()
meta = {
"db_alias": "default",
"collection": "teams",
}
Team.objects()
Cannot access member "objects" for type "Type[Team]"
Member "objects" is unknown (Pylance reportGeneralTypeIssue)
Any workaround?
When handling different types of DoesNotExist we get a false duplicate-except
try:
do_something()
except Doc.DoesNotExist:
handleDoc()
except OtherDoc.DoesNotExist: # here is the bad duplicate-except
handleOtherDoc()
`
When I lint my MongoEngine docs, I constantly get warnings about non-iterable values being used in an iterable context when I'm iterating over list fields. It would be very nice if those messages could be suppressed for fields which are, in fact, iterable.
Pylint-mongoengine does not work with the latest update of astroid (Nov. 25th 2018, 2.1.0). With 2.0.4 however, everything works smoothly (thx for that btw). Here is the error:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.6/site-packages/pylint/__main__.py", line 8, in <module>
pylint.run_pylint()
File "/usr/local/lib/python3.6/site-packages/pylint/__init__.py", line 20, in run_pylint
Run(sys.argv[1:])
File "/usr/local/lib/python3.6/site-packages/pylint/lint.py", line 1521, in __init__
linter.load_plugin_modules(self._plugins)
File "/usr/local/lib/python3.6/site-packages/pylint/lint.py", line 650, in load_plugin_modules
module = modutils.load_module_from_name(modname)
File "/usr/local/lib/python3.6/site-packages/astroid/modutils.py", line 202, in load_module_from_name
return load_module_from_modpath(dotted_name.split("."), path, use_sys)
File "/usr/local/lib/python3.6/site-packages/astroid/modutils.py", line 245, in load_module_from_modpath
module = imp.load_module(curname, mp_file, mp_filename, mp_desc)
File "/usr/local/lib/python3.6/imp.py", line 245, in load_module
return load_package(name, filename)
File "/usr/local/lib/python3.6/imp.py", line 217, in load_package
return _load(spec)
File "<frozen importlib._bootstrap>", line 684, in _load
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.6/site-packages/pylint_mongoengine/__init__.py", line 19, in <module>
from pylint_mongoengine.checkers.mongoengine import MongoEngineChecker
File "/usr/local/lib/python3.6/site-packages/pylint_mongoengine/checkers/mongoengine.py", line 23, in <module>
from pylint_mongoengine.utils import (node_is_subclass, name_is_from_qs,
File "/usr/local/lib/python3.6/site-packages/pylint_mongoengine/utils.py", line 5, in <module>
from astroid.util import YES
ImportError: cannot import name 'YES'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.