Skip to content

Linting updates#12773

Closed
trypsynth wants to merge 10 commits into
nvaccess:masterfrom
trypsynth:lintingUpdates
Closed

Linting updates#12773
trypsynth wants to merge 10 commits into
nvaccess:masterfrom
trypsynth:lintingUpdates

Conversation

@trypsynth

Copy link
Copy Markdown
Contributor

Link to issue number:

None

Summary of the issue:

I know we've been trying to cut back on linting issues. I tried to tackle this a few months back, but didn't really know what I was doing. Let me know how it looks now.

Description of how this pull request fixes the issue:

I linted a few files (buildVersion.py, XMLFormatting.py, wincon.py, and a few others). I've also created a new branch (lintingUpdates), if people wish to use it for future changes such as these.

Testing strategy:

NVDA runs from source with no issues.

Known issues with pull request:

None

Change log entries:

B=None

Code Review Checklist:

  • Pull Request description is up to date.
  • Unit tests.
  • System (end to end) tests.
  • Manual testing.
  • User Documentation.
  • Change log entry.
  • Context sensitive help for GUI changes.
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers

@trypsynth trypsynth requested a review from a team as a code owner August 24, 2021 18:52
@trypsynth trypsynth requested a review from seanbudd August 24, 2021 18:52
Comment thread tests/lint/flake8.ini
use-flake8-tabs = True
# Not all checks are replaced by flake8-tabs, however, pycodestyle is still not compatible with tabs.
use-pycodestyle-indent = False
continuation-style = hanging

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you've removed this line?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is still unanswered.

Comment thread source/vkCodes.py Outdated
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2007-2010 Michael Curran <mick@kulgan.net>, James Teh <jamie@jantrid.net>
# vkCodes.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line, and all lines which just contains the file name should be removed according to the copyright header standards on the Wiki. Also it feels a bit weird to me to modify the file just to reformat its copyright header so this should probably be reverted.

@trypsynth

Copy link
Copy Markdown
Contributor Author

Ah, my bad. Fixing both now. :)

@trypsynth

Copy link
Copy Markdown
Contributor Author

Hi, this should all be fixed now. :)

@trypsynth

Copy link
Copy Markdown
Contributor Author

Aaaah, my bad. Should be fixed now.

@trypsynth

Copy link
Copy Markdown
Contributor Author

Oh, I missed that. The reason I removed the line in flake8.ini was because it produced errors on every line, even comments, and I have no idea why.

@lukaszgo1

Copy link
Copy Markdown
Contributor

What version of flake8-tabs are you running? Current requirements file states that version 2.1.0 should be used.

@trypsynth

Copy link
Copy Markdown
Contributor Author

2.3.2. Would that effect it?

@trypsynth

Copy link
Copy Markdown
Contributor Author

Yup, that fixed it. Sorry. Re-added it.

@josephsl

josephsl commented Aug 25, 2021 via email

Copy link
Copy Markdown
Contributor

Comment thread source/buildVersion.py
os.path.basename(ref),
commit[:7])
except:
except: # noqa: E722

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this could be fixed by the following:

Suggested change
except: # noqa: E722
except Exception:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even better spend a little time understanding this function and catch only exceptions which can be raised here.

Comment thread source/versionInfo.py

import os
from buildVersion import *
from buildVersion import * # noqa: F403, F401

@seanbudd seanbudd Aug 26, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really a fix. Instead, import the required values for the strings directly, and change .format calls to use these variables.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of code - both in NVDA and in add-ons relies on versionInfo star-importing everything from buildVersion. If we really want to go this route then this would need to wait until 2022.1.

Comment thread source/XMLFormatting.py
self._commandList.append(textInfos.FieldCommand("formatChange", newAttrs))
else:
raise ValueError("Unknown tag name: %s"%tagName)
raise ValueError("Unknown tag name: %s" % tagName)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are changing this line, we should use the new standard of f-strings

Suggested change
raise ValueError("Unknown tag name: %s" % tagName)
raise ValueError(f"Unknown tag name: {tagName}")

Comment thread source/XMLFormatting.py
pass
else:
raise ValueError("unknown tag name: %s"%tagName)
raise ValueError("unknown tag name: %s" % tagName)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise ValueError("unknown tag name: %s" % tagName)
raise ValueError(f"unknown tag name: {tagName}")

@feerrenrut

Copy link
Copy Markdown
Contributor

I don't think we can accept purely linting changes like this. Our current approach is to fix linting errors as we modify code. This preserves the 'git blame' history.

I'm sorry to say this after you have spent time on this. To prevent this in the future, please create an issue and make sure it gets attention (follow up on the developers mailing list etc).

If we were to do a mass "lint fix only" change, it will need the following properties:

  • Fix one or more categories of issues for all files. This SHA can then be added to a git config file for "--ignore-revs-file".
  • Done in a reproducible and automated way. This will need to be applied to all PR's to simplify merge conflicts.

As a first step we plan to look at normalizing the line endings across the code base.
Subsequently, whitespace issues could be resolved, then any other easy to automate fix for linting errors.

Projects such as Black/Tan are code formatters for Python. They or something similar could be used to automate the re-format effort.

I'd like to close this without merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants