Skip to content

Remove future imports and python-future code#1085

Merged
tridge merged 1 commit intoArduPilot:masterfrom
cclauss:the-future-is-now
Jul 11, 2025
Merged

Remove future imports and python-future code#1085
tridge merged 1 commit intoArduPilot:masterfrom
cclauss:the-future-is-now

Conversation

@cclauss
Copy link
Contributor

@cclauss cclauss commented Jul 8, 2025

Related to

Completes

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 and ruff rule UP029 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.

How was this tested?

localhost:

source .venv/bin/activate
python -m pytest  # 1 failed, 50 passed, 8 skipped, 1 warning in 16.02s -- tests/test_mavftp.py OSError: Address already in use
python -m pip uninstall future
python -m 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?

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?___
@cclauss cclauss force-pushed the the-future-is-now branch from 69d6e5e to 0c499ff Compare July 8, 2025 05:44
Copy link
Contributor

@khancyr khancyr left a comment

Choose a reason for hiding this comment

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

Good idea !

Left some small comments without investigating much.


import sys
if sys.version_info <= (3,10):
from future import standard_library
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this needed as we still support Python 3.8 ?

Copy link
Contributor Author

@cclauss cclauss Jul 8, 2025

Choose a reason for hiding this comment

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

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Hum, need to check why this one's isn't need as I think it was added recently

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we check with division was imported and modify the code to cope ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

@cclauss cclauss requested a review from khancyr July 8, 2025 10:52
@tridge tridge merged commit 116c77c into ArduPilot:master Jul 11, 2025
20 checks passed
@cclauss cclauss deleted the the-future-is-now branch July 12, 2025 01:17
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.

4 participants