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

More fixes for Python 3 compatibility #13008

Merged
merged 4 commits into from
Dec 19, 2019

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Sep 23, 2019

Please use PX4 Discuss or Slack to align on pull requests if necessary. You can then open draft pull requests to get early feedback.

Describe problem solved by the proposed pull request
A clear and concise description of the problem this proposed change will solve. E.g. For this use case I ran into...

Test data / coverage
How was it tested? What cases were covered? Logs uploaded to https://review.px4.io/ and screenshots of the important plot parts.

Describe your preferred solution
A clear and concise description of what you have implemented.

Describe possible alternatives
A clear and concise description of alternative solutions or features you've considered.

Additional context
Add any other related context or media.

@julianoes
Copy link
Contributor

Thanks a lot @cclauss. We should get this in right after the release!

@julianoes julianoes self-requested a review October 24, 2019 06:29
@julianoes
Copy link
Contributor

@cclauss I've rebased this, fixed the conflict and force-pushed. Let's see what CI says.

@julianoes julianoes force-pushed the fix-Python-undefined-names branch from d864cd4 to b024675 Compare December 18, 2019 10:20
Copy link
Contributor

@julianoes julianoes left a comment

Choose a reason for hiding this comment

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

Thanks @cclauss!

@julianoes julianoes merged commit 6dc55f9 into PX4:master Dec 19, 2019
@cclauss cclauss deleted the fix-Python-undefined-names branch December 19, 2019 10:24
@cclauss
Copy link
Contributor Author

cclauss commented Dec 19, 2019

There are still three undefined name...

flake8 testing of https://github.com/PX4/Firmware on Python 3.8.0

$ flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics

./Tools/uorb_graph/create.py:369:70: F821 undefined name 'path'
                print('Failed reading file: %s, skipping content.' % path)
                                                                     ^
./platforms/nuttx/Debug/Nuttx.py:419:14: F821 undefined name 'regmap'
		for reg in regmap:
             ^
./platforms/nuttx/Debug/Nuttx.py:420:24: F821 undefined name 'regmap'
			hex_addr= hex(int(a[regmap[reg]]))
                       ^
3     F821 undefined name 'path'
3

https://flake8.pycqa.org/en/latest/user/error-codes.html

On the flake8 test selection, this PR does not focus on "style violations" (the majority of flake8 error codes that psf/black can autocorrect). Instead these tests are focus on runtime safety and correctness:

  • E9 tests are about Python syntax errors usually raised because flake8 can not build an Abstract Syntax Tree (AST). Often these issues are a sign of unused code or code that has not been ported to Python 3. These would be compile-time errors in a compiled language but in a dynamic language like Python they result in the script halting/crashing on the user.
  • F63 tests are usually about the confusion between identity and equality in Python. Use ==/!= to compare str, bytes, and int literals is the classic case. These are areas where a == b is True but a is b is False (or vice versa). Python >= 3.8 will raise SyntaxWarnings on these instances.
  • F7 tests logic errors and syntax errors in type hints
  • F82 tests are almost always undefined names which are usually a sign of a typo, missing imports, or code that has not been ported to Python 3. These also would be compile-time errors in a compiled language but in Python a NameError is raised which will halt/crash the script on the user.

@julianoes
Copy link
Contributor

Thanks @cclauss, see #13763.

@julianoes
Copy link
Contributor

It's odd that this now fails in CI after all:

[2019-12-19T10:21:36.058Z] + python msg/tools/uorb_to_ros_rtps_ids.py -i msg/tools/uorb_rtps_message_ids.yaml -o px4_ros_com/templates/uorb_rtps_message_ids.yaml
[2019-12-19T10:21:36.327Z] Traceback (most recent call last):
[2019-12-19T10:21:36.327Z]   File "msg/tools/uorb_to_ros_rtps_ids.py", line 11, in <module>
[2019-12-19T10:21:36.327Z]     import six
[2019-12-19T10:21:36.327Z] ImportError: No module named six
script returned exit code 1

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.

2 participants