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

Create lint_python.yml #3527

Closed
wants to merge 1 commit into from
Closed

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Mar 31, 2020

As requested at #3313 (comment) This is a exact replica of #3421

@pekkaklarck
Copy link
Member

It's good that CI runs this automatically. The run fails and those failures should obviously be fixed before this PR could be accepted. On a quick look things that should be done are:

  • Exclude atest and utest directories altogether (it seems this may have already been addressed while I'm writing this).
  • Use unicode via robot.utils everywhere. We already expose it there but apparently don't use in all places.
  • Add long to robot.utils same way as unicode. Use it where appropriate.
  • Add magic comments to unicode and long under robot.utils to ignore the linting error if needed.

- run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- run: |
EXCLUDE=./.*,./atest/testdata/*
flake8 . --count --exclude=$EXCLUDE --select=E9,F63,F7,F82 --show-source --statistics
Copy link
Member

Choose a reason for hiding this comment

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

Could this just be run for src/robot instead of of trying to exclude other directories?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we just ignore problems that appear in setup.py for instance? I think it is safer to only exclude certain test directories where you are consciously trying to break things. Also, should we just paper over the fact that this code does not follow the Python porting best practice use feature detection instead of version detection?

Copy link
Member

Choose a reason for hiding this comment

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

  1. If you think it's important to test setup.py, run linter for it in addition to src/robot. I want linting to be opt-in, not opt-out, in general and I definitely don't want it for any code under atest or utest directories.

  2. This code base uses both version detection and feature detection, depending on which is more practical. Most of the Python 2/3 differences are such that version detection is 100% safe, results with cleaner code, and is also a bit faster (try/except isn't free). Our PY3 constant is defined so that it will be true also with possible Python 4, so as long it doesn't break compatibility with Python 3 we are safe. And if it breaks, we need to fix our code anyway. Finally, this stuff is definitely not going to change before RF 4.0 when we remove Python 2 support altogether.

@codecov-io
Copy link

Codecov Report

Merging #3527 into master will decrease coverage by 1.71%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3527      +/-   ##
==========================================
- Coverage   74.12%   72.41%   -1.70%     
==========================================
  Files         199      197       -2     
  Lines       16452    16027     -425     
  Branches     2646     2636      -10     
==========================================
- Hits        12194    11605     -589     
- Misses       3823     3955     +132     
- Partials      435      467      +32     
Impacted Files Coverage Δ
src/robot/utils/encoding.py 54.91% <0.00%> (-29.41%) ⬇️
src/robot/utils/unic.py 69.85% <0.00%> (-26.98%) ⬇️
src/robot/running/runkwregister.py 68.75% <0.00%> (-25.00%) ⬇️
src/robot/utils/encodingsniffer.py 61.54% <0.00%> (-23.07%) ⬇️
src/robot/utils/compat.py 52.78% <0.00%> (-22.22%) ⬇️
src/robot/utils/robottypes.py 81.25% <0.00%> (-18.75%) ⬇️
src/robot/utils/robotpath.py 56.61% <0.00%> (-16.98%) ⬇️
src/robot/utils/etreewrapper.py 74.33% <0.00%> (-8.10%) ⬇️
src/robot/utils/robotio.py 40.39% <0.00%> (-7.69%) ⬇️
src/robot/utils/robottypes3.py 87.18% <0.00%> (-7.69%) ⬇️
... and 70 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 09c4088...f1b0c89. Read the comment docs.

@@ -125,12 +125,13 @@ def unknown(argument: Unknown, expected=None):
_validate_type(argument, expected)


def non_type(argument: 'this is string, not type', expected=None):
def non_type(argument: 'this is string, not type', # noqa: F821
expected=None):
Copy link
Member

Choose a reason for hiding this comment

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

I don't want any validation in atest and utest directories. There's lot of strange code for testing purposes and thus lot of of linting errors. I don't want them to be excluded from linting one by one.

@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from robot.utils import PY2
from robot.utils.robottypes import long, unicode
Copy link
Member

Choose a reason for hiding this comment

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

Our code style is importing everything from second level packages like robot.utils when the importing code is outside of that package. That makes it possible to change the internal package structure without breaking anything externally and listing everything that is exposed in __init__.py also makes the API better.

In other words, this import should be changed to form robot.utils import long, unicode. long probably should be explicitly exposed via robot.utils as well.

@@ -17,6 +17,7 @@
from collections import OrderedDict

from robot.utils import IRONPYTHON, PY_VERSION
from robot.utils.robottypes import long
Copy link
Member

Choose a reason for hiding this comment

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

Import via robot.utils.

@@ -45,7 +45,7 @@
html_escape, html_format, IRONPYTHON, is_string,
PY_VERSION, secs_to_timestr, seq2str2,
timestr_to_secs, unescape)

from robot.utils.robottypes import long
Copy link
Member

Choose a reason for hiding this comment

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

Add long to the above from robot.utils import ... list.

The removed line would also be a PEP-8 violation as there's now only one empty line after imports.

@@ -16,6 +16,7 @@
import sys

from .platform import IRONPYTHON, PY2
from .robottypes import unicode
Copy link
Member

Choose a reason for hiding this comment

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

In this module unicode is used only in a Python 2 only block. Perhaps using the #noqa comment would be better in this case.

def is_unicode(item):
return isinstance(item, unicode)


Copy link
Member

Choose a reason for hiding this comment

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

Please revert this change. I like having PY2 and PY3 code in separate modules in this case. Also, this PR should be only about linting.

assert_equal(unicode(nd), "{'a': u'\\xe4', u'\\xe4': 'a'}")
else:
except NameError:
Copy link
Member

Choose a reason for hiding this comment

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

NO! We definitely absolutely never ever want to have try/except in test code like this! It can too easily cause false positives. Also, if PY2 makes it a lot more clear why we have two different assertions.

The whole utest directory should be excluded from linting altogether.

@cclauss cclauss closed this Mar 31, 2020
@cclauss cclauss deleted the patch-1 branch March 31, 2020 11:18
@pekkaklarck
Copy link
Member

I got here to mention that I simplified setup.py so that it doesn't anymore need exec() that caused the linting error in e32aee9, but since you closed the PR I guess that doesn't anymore matter.

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.

None yet

3 participants