-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive invalid-unary-operand-type with elasticsearch_dsl #3258
Comments
Thanks for reporting the issue! Here's what I presume happens. The
Later on we check that We want to have support for |
Thanks for your explanations @PCManticore, things start to get clearer! I have tried to change the If I change the default value of def Q(name_or_query=(1,), **params): the However, I have seen that by commenting the def Q(name_or_query=(1,), **params):
if isinstance(name_or_query, collections_abc.Mapping):
if params:
raise ValueError('Q() cannot accept parameters when passing in a dict.')
if len(name_or_query) != 1:
raise ValueError('Q() can only accept dict with a single query ({"match": {...}}). '
'Instead it got (%r)' % name_or_query)
name, params = name_or_query.copy().popitem()
return Query.get_dsl_class(name)(_expand__to_dot=False, **params)
# if isinstance(name_or_query, Query):
# if params:
# raise ValueError('Q() cannot accept parameters when passing in a Query object.')
# return name_or_query
if hasattr(name_or_query, '_proxied'):
return name_or_query._proxied
return Query.get_dsl_class(name_or_query)(**params) How does |
@glostis Even if you change the type of the parameter, A transform like the following should do the trick:
|
Thanks @PCManticore, the code you provided does indeed do the trick! Should I open a PR on |
Adding it in |
After second thought, I'm not sure if |
Steps to reproduce
Consider the following file, which imports
elasticsearch_dsl
:Current behavior
pylint
on this file returns:Expected behavior
pylint
should not complain about this line as it is valid syntax.Q("exists", field="foo")
is of typeelasticsearch_dsl.query.Exists
which inherits fromelasticsearch_dsl.query.Query
which implements an__invert__
method, so the~
operator on such an object is legal.I am not very familiar with how
astroid
infers types, but it could be confused by the fact thatelasticsearch_dsl.query.Query
inherits fromelasticsearch_dsl.utils.DslMeta
which in turn inherits fromelasticsearch_dsl.utils.DslMeta
throughsix
'sadd_metaclass
decorator.I have seen several similar issues concerning
numpy
(#2436 for example) which were solved by adding a brain tip toastroid
. Being quite new topylint
andastroid
, I don't know if this would be a good approach to solve the problem I am facing.pylint --version output
The text was updated successfully, but these errors were encountered: