One function
get_bytes in h2non/filetype.py
The author described this change as “fix: regression for file-like obj file type detection”. It counts as a record because the check below fails on the code as it stood at 3bd71d081 and passes on 0828418ff, with nothing else changed between the two runs.
Projecth2non/filetype.py
Fix saved2022-08-05
Sharing licenceMIT · LICENSE
Change size+4 −1
What the code was meant to do, written into the code itself as a docstring
Infers the input type and reads the first 8192 bytes, returning a sliced bytearray. Args: obj: path to readable, file, bytes, bytearray or memoryview. Returns: First 8192 bytes of the file content as bytearray type. Raises: TypeError: if obj is not a supported type.
The change
| 4 | 4 | returning a sliced bytearray. | |
| 5 | 5 | ||
| 6 | 6 | Args: | |
| 7 | - | obj: path to readable, file, bytes, bytearray or memoryview. | |
| 7 | + | obj: path to readable, file-like object(with read() method), bytes, bytearray or memoryview | |
| 8 | 8 | ||
| 9 | 9 | Returns: | |
| 10 | 10 | First 8192 bytes of the file content as bytearray type. | |
| ⋯ | |||
| 26 | 26 | ||
| 27 | 27 | if isinstance(obj, pathlib.PurePath): | |
| 28 | 28 | return get_signature_bytes(obj) | |
| 29 | + | ||
| 30 | + | if hasattr(obj, 'read'): | |
| 31 | + | return get_bytes(obj.read(_NUM_SIGNATURE_BYTES)) | |
| 29 | 32 | ||
| 30 | 33 | raise TypeError('Unsupported type as file input: %s' % type(obj)) | |
The check that tells the two apart
fail→pass·tests/test_types.py::TestFileType::test_guess_jpeg
Check file tests/test_types.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it3bd71d08120794beea5633e54d6bc5ba36bae2c9
Broken version dated2022-08-05
Modulefiletype.utils
Units changedget_bytes
Fingerprinte061640916e6d9a4
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in h2non/filetype.py
- 2022-08-10get_bytes