Skip to content

Remove miscellaneous Python 2 anachronisms#1086

Merged
tridge merged 1 commit intoArduPilot:masterfrom
cclauss:remove-misc-python2-anachronisms
Jul 11, 2025
Merged

Remove miscellaneous Python 2 anachronisms#1086
tridge merged 1 commit intoArduPilot:masterfrom
cclauss:remove-misc-python2-anachronisms

Conversation

@cclauss
Copy link
Contributor

@cclauss cclauss commented Jul 8, 2025

% ruff check --select=UP009,UP018,UP021,UP039 --output-format=concise

mavftp.py:1241:21: UP018 [*] Unnecessary `bytes` call (rewrite as a literal)
mavutil.py:940:17: UP039 [*] Unnecessary parentheses after class definition
tests/snapshottests/test_wlua.py:91:9: UP021 [*] `universal_newlines` is deprecated, use `text`
tools/mavfft_isb.py:75:18: UP039 [*] Unnecessary parentheses after class definition
tools/mavftpdecode.py:33:16: UP018 [*] Unnecessary `bytes` call (rewrite as a literal)
tools/mavftpdecode.py:64:17: UP018 [*] Unnecessary `bytes` call (rewrite as a literal)
tools/python_array_test_recv.py:2:1: UP009 [*] UTF-8 encoding declaration is unnecessary
tools/python_array_test_send.py:2:1: UP009 [*] UTF-8 encoding declaration is unnecessary
Found 8 errors.
[*] 8 fixable with the `--fix` option.`

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

What other testing approaches should be considered?
What is our minimal supported Python? Python 3.7?


% ruff rule UP021

replace-universal-newlines (UP021)

Derived from the pyupgrade linter.

Fix is always available.

What it does

Checks for uses of subprocess.run that set the universal_newlines
keyword argument.

Why is this bad?

As of Python 3.7, the universal_newlines keyword argument has been
renamed to text, and now exists for backwards compatibility. The
universal_newlines keyword argument may be removed in a future version of
Python. Prefer text, which is more explicit and readable.

Example

import subprocess

subprocess.run(["foo"], universal_newlines=True)

Use instead:

import subprocess

subprocess.run(["foo"], text=True)

References

% `ruff check --select=UP009,UP018,UP021,UP039 --output-format=concise`
```
mavftp.py:1241:21: UP018 [*] Unnecessary `bytes` call (rewrite as a literal)
mavutil.py:940:17: UP039 [*] Unnecessary parentheses after class definition
tests/snapshottests/test_wlua.py:91:9: UP021 [*] `universal_newlines` is deprecated, use `text`
tools/mavfft_isb.py:75:18: UP039 [*] Unnecessary parentheses after class definition
tools/mavftpdecode.py:33:16: UP018 [*] Unnecessary `bytes` call (rewrite as a literal)
tools/mavftpdecode.py:64:17: UP018 [*] Unnecessary `bytes` call (rewrite as a literal)
tools/python_array_test_recv.py:2:1: UP009 [*] UTF-8 encoding declaration is unnecessary
tools/python_array_test_send.py:2:1: UP009 [*] UTF-8 encoding declaration is unnecessary
Found 8 errors.
[*] 8 fixable with the `--fix` option.`
```
localhost:
```bash
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
```
___What other testing approaches should be considered?___
___What is our minimal supported Python? Python 3.7?___
---
% `ruff rule UP021`
@cclauss cclauss force-pushed the remove-misc-python2-anachronisms branch from e89b3b3 to dec0140 Compare July 8, 2025 06:14
@tridge tridge merged commit 024d948 into ArduPilot:master Jul 11, 2025
20 checks passed
@cclauss cclauss deleted the remove-misc-python2-anachronisms branch July 12, 2025 01:16
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.

3 participants