jendrikseipp / vulture

Find dead Python code
MIT License
3.38k stars 148 forks source link

Add `UnicodeEncodeError` exception handling to `core.py` #300

Closed milanbalazs closed 1 year ago

milanbalazs commented 1 year ago

Description

If the code contains special characters which are not part of the latin-1 codec, the print function will be failed with an UnicodeEncodeError exception. Like below:

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 84-90: ordinal not in range(256)

If the string is encoded (default is utf-8) then the print function is able to print the related string. The users can identify the related file and line.

An example output with my change:

b"test.py:6: unused variable '\xd0\xb2\xd0\x82\xd0\x87' (60% confidence)"

Note:

Related Issue

Checklist:

codecov-commenter commented 1 year ago

Codecov Report

Merging #300 (60f36e6) into main (02bb01d) will decrease coverage by 0.46%. The diff coverage is 72.72%.

@@            Coverage Diff             @@
##             main     #300      +/-   ##
==========================================
- Coverage   99.38%   98.93%   -0.46%     
==========================================
  Files          20       20              
  Lines         655      659       +4     
==========================================
+ Hits          651      652       +1     
- Misses          4        7       +3     
Impacted Files Coverage Δ
vulture/core.py 98.52% <72.72%> (-0.88%) :arrow_down:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

jendrikseipp commented 1 year ago

Elegant solution! Thanks!