Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix an error when the first change is a binary
This fixes a bug where, in a diff where the first change is a binary file, unidiff errors with ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.9.1_5/lib/python3.9/site-packages/unidiff/patch.py", line 538, in from_filename instance = cls(f) File "/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.9.1_5/lib/python3.9/site-packages/unidiff/patch.py", line 421, in __init__ self._parse(data, encoding=encoding, metadata_only=metadata_only) File "/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.9.1_5/lib/python3.9/site-packages/unidiff/patch.py", line 520, in _parse patch_info.append(line) AttributeError: 'NoneType' object has no attribute 'append' ``` Reproduction steps: ``` \# Requires `go` to generate example binaries, but you can replace them \# with any two different binaries from any source $ echo "package main\nfunc main(){}" > binary_a.go $ go build binary_a.go $ echo "package main\nimport \"fmt\"\nfunc main(){fmt.Println(\"HI\")}" > binary_b.go $ go build binary_b.go $ diff binary_a binary_b > changes.diff $ cat changes.diff Binary files binary_a and binary_b differ $ python3 >>> from unidiff import PatchSet >>> PatchSet.from_filename('./changes.diff') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.9.1_5/lib/python3.9/site-packages/unidiff/patch.py", line 538, in from_filename instance = cls(f) File "/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.9.1_5/lib/python3.9/site-packages/unidiff/patch.py", line 421, in __init__ self._parse(data, encoding=encoding, metadata_only=metadata_only) File "/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.9.1_5/lib/python3.9/site-packages/unidiff/patch.py", line 520, in _parse patch_info.append(line) AttributeError: 'NoneType' object has no attribute 'append' >>> ```
- Loading branch information