I think I might be able to spot where the problem is. Try running
pychecker on your app folder, rather than models.py.

Let's assume your app is called myapp, so you have a directory
structure something like this:

myapp/
-- __init__.py
-- models.py
-- views.py
-- tests.py
(et cetera)

If pychecker were doing 'import myapp', then the models module would
be accessible from 'myapp.models'. Therefore, models_module's __name__
attribute would be 'myapp.models', and the code would run fine;
'myapp.models'.split('.') would return ['myapp', 'models'], and the
[-2] index of that list would be 'myapp'.

However, because you're running pychecker directly on the models.py
file, its __name__ attribute is just 'models', which raises an error
in the Django code because 'models'.split('.') returns ['models'] --
this has no [-2] index, hence the exception.

Just try running pychecker on the 'myapp/' folder (if possible), and
see if that fixes the problem.

On Jan 22, 10:22 pm, ivan <bestc...@gmail.com> wrote:
> Hi all,
>
> I'm attempting to run pychecker on my django code (an application's
> models.py file) and get the following output:
>
> $ pychecker models.py
> Processing models...
>  Caught exception importing module models:
>    File "/var/lib/python-support/python2.5/pychecker/checker.py",
> line 619, in setupMainCode()
>    File "models.py", line 538, in <module>()
>    File "/usr/lib/python2.5/site-packages/django/db/models/base.py",
> line 51, in __new__()
>  IndexError: list index out of range
>
> Warnings...
>
> models:1: NOT PROCESSED UNABLE TO IMPORT
>
> My django version is '1.0.2 final'.
>
> The IndexError happens on the final line of code extract below:
>
> # Figure out the app_label by looking one level up.
> # For 'django.contrib.sites.models', this would be 'sites'.
> model_module = sys.modules[new_class.__module__]
> kwargs = {"app_label": model_module.__name__.split('.')[-2]}
>
> I added a 'print model_module.__name__' above this line and I get the
> following output before the exception:
> django.contrib.contenttypes.models
> django.contrib.auth.models
> django.contrib.auth.models
> django.contrib.auth.models
> django.contrib.auth.models
> models
>
> Not sure if the last models that triggers the exception is the models
> file I ran pychecker on or another file? I have all my django env
> variables set up correctly and can do runserver, dbshell ,etc.
>
> Any ideas as to why pychecker on my models file would throw this
> exception in the base django models file?
>
> thanks,
> ivan.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to