Opened 17 years ago
Closed 17 years ago
#5445 closed (fixed)
Checking iterables by looking for a __iter__ attribute doesn't work on Jython
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | jython, sprintsept14 | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Jython list and tuples are iterables but don't have iter, so are incorrectly detected as non-iterables by model validation.
Attachments (5)
Change History (11)
by , 17 years ago
Attachment: | iterables.patch added |
---|
comment:1 by , 17 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
comment:2 by , 17 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
I'm not in love with the implementation. A couple of comments:
- you create _is_iterable in validation.py and then later on do almost the exact same thing in test/client.py. Why not create a file in django/utils/ called something appropriate (or use itercompat.py, which we already have) and put a utility function in there?
- Does Jython have a basestring type? We use isinstance(foo, basestring) all over the place in Django, so it'd be nice we could also use that here instead of types.StringType. Otherwise there are a lot of places you're going to have to change.
comment:3 by , 17 years ago
Looks reasonable. Not sure about the name "itercompat", though. CPython does not guarantee that all iterables have an iter method; they may just implement the tp_iter slot on the C level, or just provide a C-level sequence API. iter() handles all those cases.
comment:4 by , 17 years ago
(oh, sorry, missed that itercompat.py is an existing module. +1 from me, then)
by , 17 years ago
Attachment: | iterables3.patch added |
---|
Uses is_iterable on django.template too. Also changes the order of the typical check for the common case: now we first check for non-strings, next for iterables.
by , 17 years ago
Attachment: | iterables3.2.patch added |
---|
The previous patch file is messed up. Now it's OK.
comment:5 by , 17 years ago
Keywords: | sprintsept14 added |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Looks good to me. If you've missed something else, we can deal with that in an additional issue. Boldly tagging this and marking it as "Read for checkin".
comment:6 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Replaced iter attribute lookup by trial an error with iter()