Skip to content

Commit

Permalink
Merge 998f2a4 into 9c4be14
Browse files Browse the repository at this point in the history
  • Loading branch information
moylop260 committed Sep 10, 2021
2 parents 9c4be14 + 998f2a4 commit f8be8c7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
28 changes: 22 additions & 6 deletions pylint_odoo/checkers/no_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@
'missing-return',
settings.DESC_DFLT
),
'W%d11' % settings.BASE_NOMODULE_ID: (
'Context overridden using dict. '
'Better using kwargs "with_context(**%s)" or "with_context(key=value)"',
'context-overridden',
settings.DESC_DFLT
),

'E%d01' % settings.BASE_NOMODULE_ID: (
'The author key in the manifest file must be a string '
'(with comma separated values)',
Expand Down Expand Up @@ -208,11 +215,6 @@
'old-api7-method-defined',
settings.DESC_DFLT
),
'W%d11' % settings.BASE_NOMODULE_ID: (
'Field parameter "%s" is no longer supported. Use "%s" instead.',
'renamed-field-parameter',
settings.DESC_DFLT
),
'W%d12' % settings.BASE_NOMODULE_ID: (
'"eval" referenced detected.',
'eval-referenced',
Expand Down Expand Up @@ -245,6 +247,11 @@
'translation-positional-used',
settings.DESC_DFLT
),
'W%d17' % settings.BASE_NOMODULE_ID: (
'Field parameter "%s" is no longer supported. Use "%s" instead.',
'renamed-field-parameter',
settings.DESC_DFLT
),
'F%d01' % settings.BASE_NOMODULE_ID: (
'File "%s": "%s" not found.',
'resource-not-exist',
Expand Down Expand Up @@ -550,7 +557,7 @@ def visit_print(self, node):
'translation-required',
'translation-contains-variable',
'print-used', 'translation-positional-used',
'str-format-used',
'str-format-used', 'context-overridden',
)
def visit_call(self, node):
infer_node = utils.safe_infer(node.func)
Expand Down Expand Up @@ -612,6 +619,15 @@ def visit_call(self, node):
self.get_cursor_name(node.func) in self.config.cursor_expr:
self.add_message('invalid-commit', node=node)

if (isinstance(node, astroid.Call) and
isinstance(node.func, astroid.Attribute) and
node.func.attrname == 'with_context' and
not node.keywords and node.args):
# with_context(**ctx) is considered a keywords
# So, if only one args is received it is overridden
self.add_message('context-overridden', node=node,
args=(node.args[0].as_string(),))

# Call the message_post()
base_dirname = os.path.basename(os.path.normpath(
os.path.dirname(self.linter.current_file)))
Expand Down
1 change: 1 addition & 0 deletions pylint_odoo/test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'attribute-deprecated': 3,
'class-camelcase': 1,
'consider-merging-classes-inherited': 2,
'context-overridden': 3,
'copy-wo-api-one': 2,
'create-user-wo-reset-password': 1,
'dangerous-filter-wo-user': 1,
Expand Down
8 changes: 8 additions & 0 deletions pylint_odoo/test_repo/broken_module/models/broken_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ def method_date(self):
fields.Datetime.context_timestamp(self,
timestamp=fields.Datetime.now())
)
self.with_context({'overwrite_context': True}).write({})
ctx = {'overwrite_context': True}
self.with_context(ctx).write({})
ctx2 = ctx
self.with_context(ctx2).write({})

self.with_context(**ctx).write({})
self.with_context(overwrite_context=False).write({})
return date

my_ok_field = fields.Float(
Expand Down

0 comments on commit f8be8c7

Please sign in to comment.