-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
MAINT: Fix lgtm alerts #9292
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
MAINT: Fix lgtm alerts #9292
Conversation
The failures here are real: Python 3 no longer supports the My reading of PEP 3109 is that there is no way of having code compatible with both versions, and that the best we can do would be:
It would probably be a good idea to unpack |
numpy/f2py/crackfortran.py
Outdated
@@ -832,7 +832,7 @@ def appenddecl(decl, decl2, force=1): | |||
decl = {} | |||
if not decl2: | |||
return decl | |||
if decl is decl2: | |||
if decl == decl2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we certain that decl
will have an __eq__
method, and that this is not intentionally checking for "is the exact same object"? I'm not familiar at all with f2py
, but I wouldn't be surprised if that was the case...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it decl
and decl2
have to be dictionaries (so ==
is fine) and the following if
block will override decl
values with that of decl2
where relevant so if ==
is true that block has no effect (but does no harm, just redundant)
The only case this is not true is for setattrspec(decl, l, force)
when force
is true: if decl2 == decl
then decl['attrspec']
would be modified by having its own values appended to itself. I thought this was not desirable behaviour but you're right that someone more familiar with f2py
might want to confirm this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be inclined to change this line in another PR, and only if a failing test can be constructed with it in its current state.
The rest of this PR is uncontroversial, and would be good to get in
FWIW, the other changes seem sensible and LGTM. Thanks Jean! |
@jaimefrio you're welcome. re raising exceptions in Python3 and 2: yes I agree meaningful names would be useful. I just got lazy, will update :) re |
@jaimefrio I've modified the exception code to make it 2/3 compatible. There are 2 ways to do so and to avoid the
The discussion on which one to use might be best moved to another PR |
So far numpy has carefully avoided adding a dependency on either six or future, and instead carries around its own compatibility hacks in |
@njsmith thanks for the explanation. Bear with me as I'm not sure I understand the question: can |
Oh, I see, It looks like Anyway, I'd suggest using either |
yes, this is actually how I stumbled upon them using lgtm.com (https://lgtm.com/rules/5990074/) :)
I believe this is what |
Feel free to hack on tempita. Cython carries its own version, but warns not to rely on it, which is why it is vendored here. Tempita itself was unmaintained for a long time, recently taken over by another, and needed compatibility fixes. The Cython version probably has fixes also. I'd rather not add a six or future dependency. |
ok done. Provided no one objects the change re |
tools/npy_tempita/__init__.py
Outdated
if PY3: | ||
raise(e) | ||
raise(e_value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No parens needed here (repeated below twice)
numpy/f2py/crackfortran.py
Outdated
@@ -832,7 +832,7 @@ def appenddecl(decl, decl2, force=1): | |||
decl = {} | |||
if not decl2: | |||
return decl | |||
if decl is decl2: | |||
if decl == decl2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be inclined to change this line in another PR, and only if a failing test can be constructed with it in its current state.
The rest of this PR is uncontroversial, and would be good to get in
@eric-wieser done - I've reverted the change in |
Ideally you'd have rebased and fixed the commit message formats, but in this case it was fine just to squash down into a single commit. Thanks @jhelie! |
will keep it in mind for next time :) |
Do you want to open a separate issue for enabling lgtm on pull requests? I could do that right now, but it would be good to get feedback from some other maintainers first |
sure will do, this indeed sounds like a great idea - feedback is always welcome! |
opened #9297 |
This PR fixes issues flagged by lgtm.com code queries. Most are minor but several do fix unintentional code behaviour.
The standard lgtm deep code analysis highlights dependencies, vulnerabilities and currently flag 185 alerts but you can investigate further by writing custom queries to explore your code base (see (https://lgtm.com/projects/g/numpy/numpy/ and https://lgtm.com/docs/ql/about-ql).
PR integration can also help automatically check for potential issues before they find their way into the code base - for instance several issues were introduced when copying in tempita code in 581bb79 and could have been addressed in that PR (https://lgtm.com/projects/g/numpy/numpy/rev/581bb79c170748cbf2f6970cd53595b3b5f1fe3e)
Hope that helps!