#21862: Loading app fails with Python 3.3 resulting in: TypeError: 
'_NamespacePath'
object does not support indexing
---------------------------------+---------------------------------------
     Reporter:  elbaschid        |                    Owner:  nobody
         Type:  Bug              |                   Status:  new
    Component:  Python 3         |                  Version:  1.7-alpha-1
     Severity:  Release blocker  |               Resolution:
     Keywords:                   |             Triage Stage:  Accepted
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+---------------------------------------

Comment (by carljm):

 It looks like with the new app-loading stuff, the correct way to get the
 base path for an app is now `app_config.path`. And by default
 `app_config.path` now uses `module.__path__[0]` (which is causing this
 error) rather than `__file__` (which caused the error prompting #17304,
 pre-app-loading). We _could_ resolve this bug by changing
 `module.__path__[0]` to `list(module.__path__)[0]`, and then we would
 "support" apps that are namespace packages, although if they actually are
 multi-located namespace packages, we would be arbitrarily choosing one
 location (the first found on `sys.path`) and only supporting templates etc
 in that location and no others.

 Alternatively (and perhaps less confusingly), `AppConfig` could check for
 `len(module.__path__) > 1` and raise a clear error that apps cannot be
 namespace packages.

 Third option, and most invasive, would be to "fully" support apps as
 namespace packages, by replacing `AppConfig.path` with `AppConfig.paths`,
 and requiring any code using it (e.g. the app-directories template loader)
 to potentially look in multiple paths for each app.

 Personally I think I'd vote for the second option (raise an error); I
 think this bug was filed simply as a result of someone forgetting the
 `__init__.py`, not because there was a real use case for a namespace
 package app.

 At some point in the future when everyone is using Python 3.3+, it's
 possible that `__init__.py` becomes a historical relic and everyone just
 leaves it out as a matter of course, even when they don't really need a
 namespace package. If that happens, we would need to revisit this choice.

 (As a side note, it appears `AppStaticStorage` is still using
 `app_module.__file__` and should perhaps be updated to use
 `app_config.path`.)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21862#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.c3801765b6ec0e31bb7275de239222db%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to