Skip to content
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

pylint incorrectly issues error E1123 on numpy.unique kwargs (numpy v1.15.4) #3825

Closed
NiaX84 opened this issue Sep 10, 2020 · 10 comments
Closed
Assignees
Labels
Bug 🪲 Cannot reproduce 🤷 Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade)

Comments

@NiaX84
Copy link

NiaX84 commented Sep 10, 2020

Steps to reproduce

  1. create code calling numpy.unique with keyword arguments return_counts, return_index
  2. run pylint

Current behavior

E1123 is raised.

E1123: Unexpected keyword argument 'return_counts' in function call (unexpected-keyword-arg)

Expected behavior

no error is raised, since the keyword arguments are present since numpy v1.9.0 and numpy v1.15.4 is used

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.7.2 (default, Mar 27 2019, 08:41:08)
[GCC 6.3.0 20170516]

@hippo91
Copy link
Contributor

hippo91 commented Sep 10, 2020

@NiaX84 thanks for the report.
Can you give an example where the problem arises ?

@AWhetter
Copy link
Contributor

#3736 is a duplicate issue that contains an example for this problem.

@hippo91 hippo91 self-assigned this Sep 15, 2020
@hippo91
Copy link
Contributor

hippo91 commented Sep 27, 2020

@NiaX84 @igozali i'm unable to reproduce the bug.
I'm linting following code:

import numpy as np
xs = np.array([1, 1, 2])
np.unique(xs, return_index=False)

and i obtain:

************* Module bug_pylint_3825
bug_pylint_3825.py:1:0: C0114: Missing module docstring (missing-module-docstring)

------------------------------------------------------------------
Your code has been rated at 6.67/10 (previous run: 6.67/10, +0.00)

I'm using:

  • pylint 2.6
  • astroid 2.4
  • numpy 1.19.1

@DevinShanahan
Copy link

@hippo91 It appears the numpy version is important. I am seeing this with numpy<=1.15.4 but I get the same result as you for numpy>=1.16.

numpy 1.15.4

************* Module bug_pylint_3825
bug_pylint_3825.py:1:0: C0114: Missing module docstring (missing-module-docstring)
bug_pylint_3825.py:3:0: E1123: Unexpected keyword argument 'return_index' in function call (unexpected-keyword-arg)

---------------------------------------------------------------------
Your code has been rated at -10.00/10 (previous run: 6.67/10, -16.67)

@hippo91
Copy link
Contributor

hippo91 commented Dec 20, 2020

@DevinShanahan thanks for your answer.
Maintaining the astroid brain that handle numpy stuff is a lot of work. Honestly i don't think we are able to maintain it for all versions of numpy. I think the solution here is to upgrade you numpy version.

@hippo91 hippo91 closed this as completed Dec 20, 2020
@guy4261
Copy link

guy4261 commented Jan 21, 2021

Same for E1102: torch.tensor is not callable (not-callable) with

  • python==3.6
  • torch==1.7.0
  • pylint==2.6.0

My pylintrc file doesn't block this, even though it contains:

$ cat pylintrc
[TYPECHECK]
# List of members which are set dynamically and missed by Pylint inference
# system, and so shouldn't trigger E1101 when accessed.
generated-members=torch
ignored-classes=torch.tensor
ignored-modules=torch

I can't make this error disappear (for code such as torch.tensor([True, False]) which is valid in the repl.

@hippo91
Copy link
Contributor

hippo91 commented Jan 23, 2021

@guy4261 thanks for your report.
I think that astroid, the pylint inference engine, needs a brain to plainly support torch.
If you are interested in, it will be a pleasure to help you through.

@guy4261
Copy link

guy4261 commented Jan 23, 2021

#wat
Thanks @hippo91 but why do these ignores don't work? I don't might the false positives (hey, everyone has bugs) - they reflect something that's hard to do (identifying stuff coming from C++ I guess)? But making the ignores work is something I'd expected of pylint (=properly filter out errors, not because they are incorrect but because I had the ignored-modules=torch directive in my pylintrc file).

I ended code such as torch.tensor([1,2,3], dtype=torch.int64) to torch.Tensor([1,2,3]).to(torch.int64).
So thanks! No help required (but I'd be glad to hear your suggestions if any!).

@PCManticore
Copy link
Contributor

@guy4261 ignored-modules is not taken in consideration for not-callable or other errors you were getting here; we only use it for no-member and maybe some other checks as well. We should update the documentation or use the flag in other locations as well, but that's the reason why the ignored-modules=torch option did not do anything here.

@guy4261
Copy link

guy4261 commented Feb 7, 2021

Thanks for the clarification @PCManticore !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Cannot reproduce 🤷 Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants