Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

str/bytes problems #172

Open
srittau opened this issue Dec 23, 2022 · 0 comments
Open

str/bytes problems #172

srittau opened this issue Dec 23, 2022 · 0 comments

Comments

@srittau
Copy link

srittau commented Dec 23, 2022

While writing type stubs for ExifRead (python/typeshed#9403), I've come across a few inconsistencies/bugs that are probably related to the str/bytes changes from Python 2 to Python 3.

  1. ord_ is only ever called with a bytes argument, but checks for a str and returns a bytes argument unchanged:

def ord_(dta):
if isinstance(dta, str):
return ord(dta)
return dta

I believe this method is mostly obsolete and could be replaced by straight calls to ord().

  1. special_mode() in tags/makernote/olympus.py is (I think) passed a bytes string and returns a regular str. But in the case where the passed in string is empty, it will just return it unchanged (i.e. it will return bytes instead of str), possibly raise a TypeError:

def special_mode(val):
"""Decode Olympus SpecialMode tag in MakerNote"""
mode1 = {
0: 'Normal',
1: 'Unknown',
2: 'Fast',
3: 'Panorama',
}
mode2 = {
0: 'Non-panoramic',
1: 'Left to right',
2: 'Right to left',
3: 'Bottom to top',
4: 'Top to bottom',
}
if not val:
return val
mode1_val = mode1.get(val[0], "Unknown")
mode2_val = mode2.get(val[2], "Unknown")
return '%s - Sequence %d - %s' % (mode1_val, val[1], mode2_val)

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

No branches or pull requests

1 participant