Summary: | app-portage/mirrorselect python3 incompatibility - TypeError: sequence item 1: expected str instance, bytes found | ||
---|---|---|---|
Product: | Gentoo Linux | Reporter: | Justin Lecher (RETIRED) <jlec> |
Component: | Current packages | Assignee: | Portage Tools Team <tools-portage> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | pacho |
Priority: | Normal | Keywords: | InVCS |
Version: | unspecified | ||
Hardware: | All | ||
OS: | Linux | ||
Whiteboard: | |||
Package list: | Runtime testing required: | --- | |
Attachments: |
map hosts to str
another attempt |
Description
Justin Lecher (RETIRED)
2017-02-19 14:30:03 UTC
Created attachment 464362 [details, diff]
map hosts to str
This patch might help. I can't see exactly what the problem is here as it works ok on my machine. If the output is garbled I will look further.
Comment on attachment 464362 [details, diff] map hosts to str This patch is obviously incorrect and would result in 'BytesWarning: str() on a bytes instance'. As you can see below, str(bytes) results in b' prefix and ' suffix in resulting string: $ python -bq >>> str(b"a") __main__:1: BytesWarning: str() on a bytes instance "b'a'" >>> b"a".decode("utf-8") 'a' >>> Created attachment 464458 [details, diff]
another attempt
Ah sorry. I'm guessing the problem is only the first host is checked if it is encoded.
if hasattr(hosts[i], 'decode'): should be if isinstance(hosts[i], bytes): (In reply to zakalwe from comment #3) > Created attachment 464458 [details, diff] [details, diff] > another attempt > > Ah sorry. I'm guessing the problem is only the first host is checked if it > is encoded. Yeah, In all my testing, if it was either ascii or bytes for all entries. I'm wondering if either someone pushed some ascii into the list of more probable, the first entry was a null string. Thanks, no need to make a new patch, I'll change it to use isinstance() instead. I was thinking this morning I might do it in a one-line generator, but this is clearer. Thank you. Pushed in commit: https://gitweb.gentoo.org/proj/mirrorselect.git/commit/?id=c91509d823c27fdb1527c61f77c959b305170915 I've added a little fixup here: https://gitweb.gentoo.org/proj/mirrorselect.git/commit/?id=18df6efa96f57830f26ca94c41e1f1e8cc30b3ca Thanks Zac. That was a Duh moment... I blame working on unit tests all day where I was having to put nearly everything in quotes. I must have hit undo in the editor without noticing I undid that fix. By the way, when committing this fix, it would be nice to add support for python3.5 and 3.6 if possible ;) Thanks Is this a matter of preparing a new release with this and other fixes or applying the patches would be enough? Thanks :) yes, I'll get a release out this weekend. Thanks for the reminder... 2.2.3 was released |