Remove future imports and python-future code#1085
Conversation
Completes * ArduPilot#1048 > ### the future is here https://python-future.org/whatsnew.html > The new version number of 1.0.0 indicates that the `python-future` project, like Python 2, is now done. Start with `ruff rule UP010` [unnecessary-future-import](https://docs.astral.sh/ruff/rules/unnecessary-future-import) and `ruff rule UP029` [unnecessary-builtin-import](https://docs.astral.sh/ruff/rules/unnecessary-builtin-import). % `ruff check --select=UP --statistics` ``` 641 UP031 [ ] printf-string-formatting 57 UP004 [*] useless-object-inheritance 48 UP029 [ ] unnecessary-builtin-import # <-- This pull request 48 UP032 [*] f-string 27 UP008 [ ] super-call-with-parameters 21 UP024 [*] os-error-alias 18 UP030 [ ] format-literals 13 UP006 [ ] non-pep585-annotation 13 UP015 [*] redundant-open-modes 8 UP010 [*] unnecessary-future-import # <-- This pull request 5 UP035 [ ] deprecated-import 3 UP018 [*] native-literals 2 UP009 [*] utf8-encoding-declaration 2 UP039 [*] unnecessary-class-parentheses 1 UP020 [*] open-alias 1 UP021 [*] replace-universal-newlines 1 UP022 [ ] replace-stdout-stderr Found 909 errors. [*] 156 fixable with the `--fix` option (530 hidden fixes can be enabled with the `--unsafe-fixes` option). ``` 1. `ruff check --select=UP010 --fix # from __future__ import ...` 2. `ruff check --select=UP029 --fix --unsafe-fixes # from builtins import ...` 3. `git grep future ` # Remove instances related to the python-future dependency. localhost: ```bash source .venv/bin/activate pytest # 1 failed, 50 passed, 8 skipped, 1 warning in 16.02s -- tests/test_mavftp.py OSError: Address already in use pip uninstall future pytest # 1 failed, 50 passed, 8 skipped, 1 warning in 16.02s -- tests/test_mavftp.py OSError: Address already in use ``` ___What other testing approaches should be considered?___
69d6e5e to
0c499ff
Compare
khancyr
left a comment
There was a problem hiding this comment.
Good idea !
Left some small comments without investigating much.
|
|
||
| import sys | ||
| if sys.version_info <= (3,10): | ||
| from future import standard_library |
There was a problem hiding this comment.
Isn't this needed as we still support Python 3.8 ?
There was a problem hiding this comment.
This if statement was added at 19ccb4e mavgen: cope with python 3.12
Because the future library became incompatible with later versions of Python. This was fixed in v1 (see the whatsnew URL above).
Importing standard_library does not help Python 3, but instead enables Python 2 code to resemble Python 3 code. This import is not needed in Python 3.
What is our minimum supported Python? 3.7 or 3.8 or 3.9? Is that documented somewhere?
| future>=0.15.2 | ||
| wheel>=0.37.1 | ||
| setuptools>=42 | ||
| fastcrc |
There was a problem hiding this comment.
Hum, need to check why this one's isn't need as I think it was added recently
There was a problem hiding this comment.
I sorted the dependencies so that fastcrc is now on line 1.
Sorting dependencies makes it easy to spot missing deps and nearly impossible to create duplicates.
| Quaternion implementation for use in pymavlink | ||
| """ | ||
|
|
||
| from __future__ import absolute_import, division |
There was a problem hiding this comment.
Shouldn't we check with division was imported and modify the code to cope ?
There was a problem hiding this comment.
These four __future__ imports change the Python 2 runtime to work like Python 3. They do not change Python 3 runtime behaviour.
For instance, importing print_function makes old-style print statements SyntaxErrors in Python 2!
Similarly, importing division changes Python 2 to divide like Python 3.
Related to
Completes
https://python-future.org/whatsnew.html
Start with
ruff rule UP010unnecessary-future-import andruff rule UP029unnecessary-builtin-import.%
ruff check --select=UP --statisticsruff check --select=UP010 --fix # from __future__ import ...ruff check --select=UP029 --fix --unsafe-fixes # from builtins import ...git grep future# Remove instances related to the python-future dependency.How was this tested?
localhost:
What other testing approaches should be considered?