Skip to content

generator: Remove dead code sha256_test.py#1081

Merged
tridge merged 1 commit intoArduPilot:masterfrom
cclauss:generator-remove-dead-code-sha256_test.py
Jul 11, 2025
Merged

generator: Remove dead code sha256_test.py#1081
tridge merged 1 commit intoArduPilot:masterfrom
cclauss:generator-remove-dead-code-sha256_test.py

Conversation

@cclauss
Copy link
Contributor

@cclauss cclauss commented Jul 6, 2025

Fixes: #1062

This file defines no classes or functions. It can only be run on the command line, but it will always fail on Python 3.

Given that it is only a command-line tool and has not been used on Python 3, let's remove it as dead code.


A TypeError will be raised if this script is run on Python 3 in its current form:

>>> import hashlib
>>> hashlib.new('sha256').update(b'bytes')  # OK
>>> hashlib.new('sha256').update('str'). # Fails!
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    hashlib.new('sha256').update('str')
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
TypeError: Strings must be encoded before hashing
>>> hashlib.new('sha256').update('str'.encode('utf-8'))  # OK

The problem is that sys.argv is a list of str, but hashlib.new('sha256').update() requires bytes, not str in Python 3.

This is not a problem in Py2 (bytes == str is True), but is a problem in Py3 (bytes == str is False).

@cclauss cclauss force-pushed the generator-remove-dead-code-sha256_test.py branch from 3845304 to 8eb57d7 Compare July 6, 2025 01:01
Fixes: ArduPilot#1062
* ArduPilot#1062

This file defines no classes or functions.  It can only be run on the command line, but it will always fail on Python 3.

Given that it is only a command-line tool and has not been used on Python 3, let's remove it as dead code.

---

A TypeError will be raised if this script is run on Python 3 in its current form:
```python
>>> import hashlib
>>> hashlib.new('sha256').update(b'bytes')  # OK
>>> hashlib.new('sha256').update('str'). # Fails!
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    hashlib.new('sha256').update('str')
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
TypeError: Strings must be encoded before hashing
>>> hashlib.new('sha256').update('str'.encode('utf-8'))  # OK
```

The problem is that `sys.argv` is a list of `str`, but `hashlib.new('sha256').update()` requires `bytes`, not `str` in Python 3.

This is not a problem in Py2 (`bytes == str` is True), but is a problem in Py3 (`bytes == str` is False).
@tridge tridge merged commit 2fb13b6 into ArduPilot:master Jul 11, 2025
20 checks passed
@cclauss cclauss deleted the generator-remove-dead-code-sha256_test.py branch July 12, 2025 01:19
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