Opened 16 years ago

Closed 16 years ago

#7847 closed (fixed)

[Cleanup] Unused imported modules in Django

Reported by: Julien Phalip Owned by: Adrian Holovaty
Component: Uncategorized Version: dev
Severity: Keywords: cleanup
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've removed many import statements of modules that were not used, throughout Django (see patch attached). That won't necessarily improve performance but it's a good cleanup at least. I ran the full test suite several times. I do get some failures/errors but I don't think they're linked to the changes in the patch since I get the exact same errors from a clean check out. My test environment (based on Windows XP+MySQL) is probably not 100% reliable and there might also be some problems caused by the latest big changes in trunk. Just for the record, here is a sample of the failures/errors I get:

======================================================================
FAIL: Doctest: modeltests.delete.models.__test__.API_TESTS
----------------------------------------------------------------------
Traceback (most recent call last):
  File "E:\Software\workspace\django\django\test\_doctest.py", line 2180, in run
Test
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for modeltests.delete.models.__test__.API_TE
STS
  File "E:\Software\workspace\django-clean\tests\modeltests\delete\models.py", l
ine unknown line number, in API_TESTS

----------------------------------------------------------------------
File "E:\Software\workspace\django-clean\tests\modeltests\delete\models.py", lin
e ?, in modeltests.delete.models.__test__.API_TESTS
Failed example:
    del D._meta._related_objects_cache
Exception raised:
    Traceback (most recent call last):
      File "E:\Software\workspace\django\django\test\_doctest.py", line 1267, in
 __run
        compileflags, 1) in test.globs
      File "<doctest modeltests.delete.models.__test__.API_TESTS[17]>", line 1,
in <module>
        del D._meta._related_objects_cache
    AttributeError: _related_objects_cache


======================================================================
FAIL: Doctest: regressiontests.string_lookup.models.__test__.API_TESTS
----------------------------------------------------------------------
Traceback (most recent call last):
  File "E:\Software\workspace\django\django\test\_doctest.py", line 2180, in run
Test
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for regressiontests.string_lookup.models.__t
est__.API_TESTS
  File "E:\Software\workspace\django-clean\tests\regressiontests\string_lookup\m
odels.py", line unknown line number, in API_TESTS

----------------------------------------------------------------------
File "E:\Software\workspace\django-clean\tests\regressiontests\string_lookup\mod
els.py", line ?, in regressiontests.string_lookup.models.__test__.API_TESTS
Failed example:
    Foo.objects.get(friend__contains=u'\xe7')
Exception raised:
    Traceback (most recent call last):
      File "E:\Software\workspace\django\django\test\_doctest.py", line 1267, in
 __run
        compileflags, 1) in test.globs
      File "<doctest regressiontests.string_lookup.models.__test__.API_TESTS[18]
>", line 1, in <module>
        Foo.objects.get(friend__contains=u'\xe7')
      File "E:\Software\workspace\django\django\db\models\manager.py", line 82,
in get
        return self.get_query_set().get(*args, **kwargs)
      File "E:\Software\workspace\django\django\db\models\query.py", line 302, i
n get
        % self.model._meta.object_name)
    DoesNotExist: Foo matching query does not exist.
----------------------------------------------------------------------
File "E:\Software\workspace\django-clean\tests\regressiontests\string_lookup\mod
els.py", line ?, in regressiontests.string_lookup.models.__test__.API_TESTS
Failed example:
    Foo.objects.get(friend__contains='\xc3\xa7')
Exception raised:
    Traceback (most recent call last):
      File "E:\Software\workspace\django\django\test\_doctest.py", line 1267, in
 __run
        compileflags, 1) in test.globs
      File "<doctest regressiontests.string_lookup.models.__test__.API_TESTS[19]
>", line 1, in <module>
        Foo.objects.get(friend__contains='\xc3\xa7')
      File "E:\Software\workspace\django\django\db\models\manager.py", line 82,
in get
        return self.get_query_set().get(*args, **kwargs)
      File "E:\Software\workspace\django\django\db\models\query.py", line 302, i
n get
        % self.model._meta.object_name)
    DoesNotExist: Foo matching query does not exist.


======================================================================
FAIL: Doctest: regressiontests.model_inheritance_regress.models.__test__.API_TES
TS
----------------------------------------------------------------------
Traceback (most recent call last):
  File "E:\Software\workspace\django\django\test\_doctest.py", line 2180, in run
Test
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for regressiontests.model_inheritance_regres
s.models.__test__.API_TESTS
  File "E:\Software\workspace\django-clean\tests\regressiontests\model_inheritan
ce_regress\models.py", line unknown line number, in API_TESTS

----------------------------------------------------------------------
File "E:\Software\workspace\django-clean\tests\regressiontests\model_inheritance
_regress\models.py", line ?, in regressiontests.model_inheritance_regress.models
.__test__.API_TESTS
Failed example:
    [sorted(d.items()) for d in dicts]
Expected:
    [[('name', u"Guido's House of Pasta"), ('serves_hot_dogs', True)]]
Got:
    [[('name', u"Guido's House of Pasta"), ('serves_hot_dogs', 1)]]
----------------------------------------------------------------------
File "E:\Software\workspace\django-clean\tests\regressiontests\model_inheritance
_regress\models.py", line ?, in regressiontests.model_inheritance_regress.models
.__test__.API_TESTS
Failed example:
    [sorted(d.items()) for d in dicts]
Expected:
    [[('name', u"Guido's House of Pasta"), ('serves_gnocchi', True), ('serves_ho
t_dogs', True)]]
Got:
    [[('name', u"Guido's House of Pasta"), ('serves_gnocchi', 1), ('serves_hot_d
ogs', 1)]]
----------------------------------------------------------------------
File "E:\Software\workspace\django-clean\tests\regressiontests\model_inheritance
_regress\models.py", line ?, in regressiontests.model_inheritance_regress.models
.__test__.API_TESTS
Failed example:
    [sorted(d.items()) for d in dicts]
Expected:
    [[('name', u"Guido's All New House of Pasta"), ('serves_hot_dogs', False)]]
Got:
    [[('name', u"Guido's All New House of Pasta"), ('serves_hot_dogs', 0)]]
----------------------------------------------------------------------
File "E:\Software\workspace\django-clean\tests\regressiontests\model_inheritance
_regress\models.py", line ?, in regressiontests.model_inheritance_regress.models
.__test__.API_TESTS
Failed example:
    [sorted(d.items()) for d in dicts]
Expected:
    [[('name', u"Guido's All New House of Pasta"), ('serves_gnocchi', False), ('
serves_hot_dogs', False)]]
Got:
    [[('name', u"Guido's All New House of Pasta"), ('serves_gnocchi', 0), ('serv
es_hot_dogs', 0)]]
----------------------------------------------------------------------
File "E:\Software\workspace\django-clean\tests\regressiontests\model_inheritance
_regress\models.py", line ?, in regressiontests.model_inheritance_regress.models
.__test__.API_TESTS
Failed example:
    [sorted(d.items()) for d in dicts]
Expected:
    [[('name', u"Guido's All New House of Pasta"), ('serves_gnocchi', False), ('
serves_hot_dogs', False)]]
Got:
    [[('name', u"Guido's All New House of Pasta"), ('serves_gnocchi', 0), ('serv
es_hot_dogs', 0)]]


----------------------------------------------------------------------
Ran 406 tests in 3574.203s

FAILED (failures=5, errors=6)

Attachments (3)

unused.imports.diff (124.8 KB ) - added by Julien Phalip 16 years ago.
unused.imports.r8002.diff (18.9 KB ) - added by Julien Phalip 16 years ago.
First patch was not rendered properly
result_tests.txt (48.1 KB ) - added by Julien Phalip 16 years ago.
Output of tests run on Windows XP + MySQL

Download all attachments as: .zip

Change History (7)

by Julien Phalip, 16 years ago

Attachment: unused.imports.diff added

by Julien Phalip, 16 years ago

Attachment: unused.imports.r8002.diff added

First patch was not rendered properly

comment:1 by Julien Phalip, 16 years ago

From the error messages above, I just realised that there's a mix up between 2 checkouts of django (in the test errors, not the patch), so I'll try to run another test suite today and will post an update here. Feel free to give it a shot on your own test environment too.

by Julien Phalip, 16 years ago

Attachment: result_tests.txt added

Output of tests run on Windows XP + MySQL

comment:2 by Julien Phalip, 16 years ago

Ok, I really struggled to run the whole test suite. I tried multiple times and consistently get some errors and failures. Some originate from known issues in Windows [1], and others I really don't understand why I get them (e.g. all the Permission Denied ones).
My environment is apparently not the best to run the tests. If you're keen, you can run the tests and see if the patch doesn't break anything. Feel free to close and wontfix the ticket if you feel it's not worth it.

[1] http://code.djangoproject.com/wiki/DjangoOnWindows

comment:3 by Adrian Holovaty, 16 years ago

Owner: changed from nobody to Adrian Holovaty
Status: newassigned
Triage Stage: UnreviewedAccepted

comment:4 by Adrian Holovaty, 16 years ago

Resolution: fixed
Status: assignedclosed

(In [8046]) Fixed #7847 -- Removed a whole bunch of unused imports from throughout the codebase. Thanks, julien

Note: See TracTickets for help on using tickets.
Back to Top