[FIX] test_lint: deprecation warnings in pylint 3
Runbot currently doesn't use Pylint 3 in order to still have "style" lints (since removed), however compatibility with pylint 3 is useful to run tests / lints locally (and possibly eventually in future python versions for which 2 might not be compatible). Fix a few deprecation warnings: - the `__implements__` magic thing has been deprecated - `check_messages` has been renamed to `only_required_for_messages` (better explains the purpose) Also remove second parameter of `is_message_enabled` call, if specified it's supposed to be a `Confidence` value, not a number. Recent pylints changed the way it's checked, so it now errors even if not using the confidence system (or something like that). closes odoo/odoo#107960 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import os
|
||||
|
||||
import astroid
|
||||
from pylint import checkers, interfaces
|
||||
from pylint.checkers import BaseChecker
|
||||
try:
|
||||
from pylint.checkers.utils import only_required_for_messages
|
||||
except ImportError:
|
||||
from pylint.checkers.utils import check_messages as only_required_for_messages
|
||||
|
||||
|
||||
class OdooBaseChecker(checkers.BaseChecker):
|
||||
__implements__ = interfaces.IAstroidChecker
|
||||
class OdooBaseChecker(BaseChecker):
|
||||
name = 'odoo'
|
||||
|
||||
msgs = {
|
||||
@@ -16,7 +16,7 @@ class OdooBaseChecker(checkers.BaseChecker):
|
||||
)
|
||||
}
|
||||
|
||||
@checkers.utils.check_messages('gettext-variable')
|
||||
@only_required_for_messages('gettext-variable')
|
||||
def visit_call(self, node):
|
||||
if isinstance(node.func, astroid.Name) and node.func.name in ('_', '_lt'):
|
||||
first_arg = node.args[0]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import contextlib
|
||||
import contextvars
|
||||
import os
|
||||
from collections import deque
|
||||
from contextlib import ExitStack
|
||||
from typing import Optional
|
||||
|
||||
@@ -9,10 +10,13 @@ try:
|
||||
from astroid import NodeNG
|
||||
except ImportError:
|
||||
from astroid.node_classes import NodeNG
|
||||
from pylint import checkers, interfaces
|
||||
from pylint.checkers import BaseChecker, utils
|
||||
from collections import deque
|
||||
|
||||
import pylint.interfaces
|
||||
from pylint.checkers import BaseChecker, utils
|
||||
try:
|
||||
from pylint.checkers.utils import only_required_for_messages
|
||||
except ImportError:
|
||||
from pylint.checkers.utils import check_messages as only_required_for_messages
|
||||
|
||||
DFTL_CURSOR_EXPR = [
|
||||
'self.env.cr', 'self._cr', # new api
|
||||
@@ -41,8 +45,16 @@ def push_call(node: astroid.Call):
|
||||
s.callback(root_call.reset, t)
|
||||
yield
|
||||
|
||||
def parse_version(s):
|
||||
# can't use odoo.tools.parse_version because pythonpath is screwed from
|
||||
# inside pylint on runbot
|
||||
return [s.rjust(3, '0') for s in s.split('.')]
|
||||
|
||||
class OdooBaseChecker(BaseChecker):
|
||||
__implements__ = interfaces.IAstroidChecker
|
||||
# `test_printf` fails if this is not set in 2.5 (???), but it's deprecated
|
||||
# in 2.14, so make conditional
|
||||
if parse_version(pylint.__version__) < parse_version('2.14.0'):
|
||||
__implements__ = pylint.interfaces.IAstroidChecker
|
||||
name = 'odoo'
|
||||
|
||||
msgs = {
|
||||
@@ -323,16 +335,16 @@ class OdooBaseChecker(BaseChecker):
|
||||
return is_concatenation
|
||||
return True
|
||||
|
||||
@checkers.utils.check_messages('sql-injection')
|
||||
@only_required_for_messages('sql-injection')
|
||||
def visit_call(self, node):
|
||||
if not self.linter.is_message_enabled('E8501', node.lineno, node.lineno):
|
||||
if not self.linter.is_message_enabled('E8501', node.lineno):
|
||||
return
|
||||
if self._check_sql_injection_risky(node):
|
||||
self.add_message('sql-injection', node=node, args='')
|
||||
|
||||
@checkers.utils.check_messages('sql-injection')
|
||||
@only_required_for_messages('sql-injection')
|
||||
def visit_functiondef(self, node):
|
||||
if not self.linter.is_message_enabled('E8501', node.lineno, node.lineno):
|
||||
if not self.linter.is_message_enabled('E8501', node.lineno):
|
||||
return
|
||||
if os.path.basename(self.linter.current_file).startswith('test_'):
|
||||
return
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import astroid
|
||||
from pylint import checkers, interfaces
|
||||
from pylint import checkers
|
||||
|
||||
|
||||
class OdooBaseChecker(checkers.BaseChecker):
|
||||
__implements__ = interfaces.IAstroidChecker
|
||||
name = 'odoo'
|
||||
|
||||
msgs = {
|
||||
|
||||
@@ -56,7 +56,6 @@ class TestSqlLint(TransactionCase):
|
||||
'--output-format=json',
|
||||
f.name,
|
||||
],
|
||||
check=False,
|
||||
stdout=PIPE, encoding='utf-8',
|
||||
env={
|
||||
**os.environ,
|
||||
|
||||
Reference in New Issue
Block a user