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

TypeError in python 3.6 #25

Open
caver456 opened this issue May 9, 2017 · 7 comments
Open

TypeError in python 3.6 #25

caver456 opened this issue May 9, 2017 · 7 comments

Comments

@caver456
Copy link
Contributor

caver456 commented May 9, 2017

I have a program (github.com/ncssar/radiolog) that makes various calls to fdfgen. Python 3.6 (but not 3.4) generates a Type Error on startswith if the value is bytes:

Traceback (most recent call last):
File "radiolog.py", line 3413, in accept
self.parent.parent.printClueReport(clueData)
File "radiolog.py", line 1511, in printClueReport
fdf=forge_fdf("",fields,[],[],[])
File "C:\Python36\lib\site-packages\fdfgen_init_.py", line 136, in forge_fdf
checkbox_checked_name)))
File "C:\Python36\lib\site-packages\fdfgen_init_.py", line 75, in handle_data_strings
value = FDFIdentifier(checkbox_checked_name).value
File "C:\Python36\lib\site-packages\fdfgen_init_.py", line 52, in init
if value.startswith('/'):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str

and if I try hardcoding line 52 to bytes instead, I get the opposite TypeError:

Traceback (most recent call last):
File "radiolog.py", line 3413, in accept
self.parent.parent.printClueReport(clueData)
File "radiolog.py", line 1511, in printClueReport
fdf=forge_fdf("",fields,[],[],[])
File "C:\Python36\lib\site-packages\fdfgen_init_.py", line 136, in forge_fdf
checkbox_checked_name)))
File "C:\Python36\lib\site-packages\fdfgen_init_.py", line 77, in handle_data_strings
value = FDFIdentifier('Off').value
File "C:\Python36\lib\site-packages\fdfgen_init_.py", line 52, in init
if value.startswith(b'/'):
TypeError: startswith first arg must be str or a tuple of str, not bytes

I think the solution is just to place the type check and conversion code before the startswith clause instead of after.

Old:

    if value.startswith('/'):
        value = value[1:]

    if isinstance(value, bytes):
        value = value.decode('utf-8')

New: (just swapped the two clauses)

    if isinstance(value, bytes):
        value = value.decode('utf-8')

    if value.startswith('/'):
        value = value[1:]

This works in my program on python 3.6, but, I'm not an expert. Let me know if I should do this as a fork and pull request instead.

Thanks. This project has been very helpful!

@thraxil
Copy link
Contributor

thraxil commented May 9, 2017

Pull requests definitely welcome :)

@caver456
Copy link
Contributor Author

caver456 commented May 9, 2017

done - also I was mistaken about the TypeError not showing up in 3.4: I actually was not able to test the current version of fdfgen with python 3.4 for some local install oddity reasons, so, I'm not sure if it shows up in 3.4 or not.

@sontek
Copy link

sontek commented Nov 20, 2017

This is fixed, correct?

@caver456
Copy link
Contributor Author

caver456 commented Nov 21, 2017 via email

@sontek
Copy link

sontek commented Nov 21, 2017

I tested on python3.6 and everything seems to be working.

thraxil added a commit that referenced this issue Nov 21, 2017
looks like we forgot to cut a new release after merging a fix. See #25
@thraxil
Copy link
Contributor

thraxil commented Nov 21, 2017

Yeah, sorry. Looks like we forgot to cut a release after that merge. PR in for it now.

@thraxil
Copy link
Contributor

thraxil commented Nov 21, 2017

0.16.1 should be up on PyPI now.

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

3 participants