Opened 5 years ago

Closed 5 years ago

#16225 closed Cleanup/optimization (fixed)

Unused imports all over the source

Reported by: Jeffrey Gelens Owned by: Aymeric Augustin
Component: Uncategorized Version: 1.3
Severity: Normal Keywords: dceu2011
Cc: jeffrey@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


During the sprints I noticed a lot unused import are being done (checked via Pyflakes). I've talked with Russel about this and we decided to create a ticket. Well here it is.

Attachments (3)

16225.patch (133.1 KB) - added by Aymeric Augustin 5 years ago.
16225.2.diff (132.4 KB) - added by Jannis Leidel 5 years ago.
Updated patch for r16387.
16225.3.diff (137.5 KB) - added by Aymeric Augustin 5 years ago.
updated patch for r16529

Download all attachments as: .zip

Change History (14)

comment:1 Changed 5 years ago by Jeffrey Gelens

Cc: jeffrey@… added
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 5 years ago by melinath

Triage Stage: UnreviewedAccepted

comment:3 Changed 5 years ago by Aymeric Augustin

This should be fixed carefully because some apparently unused imports provide backwards compatibility, when functions or classes were moved from one module to another.

comment:4 Changed 5 years ago by Aymeric Augustin

Owner: changed from nobody to Aymeric Augustin

comment:5 Changed 5 years ago by Aymeric Augustin

  • When an import is no longer used, I used my judgement to determine if it could be removed without hurting backwards compatibility, for instance:
    • It's generally unsafe to remove imports from files (I touched only a few of these).
    • It's safe to remove from django.conf import settings when settings aren't used, except in the request handlers where we want the side effects of importing the settings for the first time.
    • It's safe to remove unused imports in trunk/tests, because third-party code shouldn't rely on them, except TestCases imported in
    • UserSettingsHolder is not documented, it's an internal API, so it's safe to remove it from django/db/models/sql/
    • OneToOneField is usually imported from django.db.models, so it's safe to remove it from django/db/models/
    • etc.
  • I did not check from ... import * statements — they should be avoided in most cases anyway :)
  • I proof read the whole patch before submitting it, and I'm rather confident that it's harmless for backwards compatibility. Obviously, the test suite still passes.
  • It removes django.contrib.admin.views.main.ORDER_TYPE_VAR which is not used anywhere.
  • It uses functools.wraps instead of django.utils.unittest.compatibility.wraps which was a Python 2.4 fallback, but it keeps the alias on which some third-party code must rely.
  • When imports span several lines, I used parentheses for continuation instead of backslashes (except in our copy of unittest, which I didn't want to alter).
  • I wrote consistently the fallback from cStringIO to StringIO and from cPickle to pickle, except in django/contrib/gis/geos/tests/ where there is a bizarre comment.

Technical note: I did the cleanup with the script available here: because pylint dies on django's source (even after increasing the limit on the number of open files, I get AttributeError: 'NoneType' object has no attribute '_infer_name'). This script uses static analysis, so it's not 100% reliable, but it works well in non-pathological cases.

  • For the record, here is the list of what I did: K = kept, R = removed.
K   django/conf/app_template/ models
K   django/conf/project_template/ include, url
R   django/contrib/admin/templatetags/ ORDER_TYPE_VAR, SortedDict
K   django/contrib/admin/ ACTION_CHECKBOX_NAME, AdminSite, AllValuesFieldListFilter, BooleanFieldListFilter, ChoicesFieldListFilter, DateFieldListFilter, FieldListFilter, HORIZONTAL, ListFilter, ModelAdmin, RelatedFieldListFilter, SimpleListFilter, StackedInline, TabularInline, VERTICAL
R   django/contrib/admindocs/ templatetags
R   django/contrib/auth/ connection
R   django/contrib/auth/tests/ warnings
R   django/contrib/auth/tests/ AnonymousUser
K   django/contrib/auth/tests/ AnonymousUserBackendTest, AuthContextProcessorTests, AuthenticationFormTest, BackendTest, BasicTestCase, ChangePasswordTest, GetDefaultUsernameTestCase, InActiveUserBackendTest, LoginRequiredTestCase, LoginTest, LoginURLSettings, LogoutTest, NoAnonymousUserBackendTest, NoBackendsTest, NoInActiveUserBackendTest, PasswordChangeFormTest, PasswordResetFormTest, PasswordResetTest, ProfileTestCase, RemoteUserCustomTest, RemoteUserNoCreateTest, RemoteUserTest, RowlevelBackendTest, SetPasswordFormTest, SignalTestCase, TestAuthPermissions, TokenGeneratorTest, UserChangeFormTest, UserCreationFormTest
R   django/contrib/auth/ datetime
K   django/contrib/databrowse/ DatabrowsePlugin, DatabrowseSite, ModelDatabrowse, site
R   django/contrib/formtools/ pickle, settings
R   django/contrib/formtools/ BooleanField
R   django/contrib/formtools/wizard/storage/ UploadedFile
K   django/contrib/formtools/wizard/storage/ BaseStorage, NoFileStorageConfigured
R   django/contrib/formtools/wizard/ copy
K   django/contrib/formtools/wizard/ FormWizard
R   django/contrib/gis/admin/ settings
K   django/contrib/gis/admin/ AdminSite, GeoModelAdmin, HORIZONTAL, ModelAdmin, OSMGeoAdmin, OpenLayersWidget, StackedInline, TabularInline, VERTICAL, autodiscover, site
R   django/contrib/gis/db/backends/ settings
R   django/contrib/gis/db/backends/oracle/ GeometryField
R   django/contrib/gis/db/models/ GeomField
R   django/contrib/gis/db/models/ GeoWhereNode, GeometryField, Q
R   django/contrib/gis/db/models/sql/ GeomField
R   django/contrib/gis/db/models/sql/ Field
K   django/contrib/gis/db/models/sql/ AreaField, DistanceField, GeoQuery, GeoWhereNode, GeomField
K   django/contrib/gis/db/models/ GeoManager, GeometryCollectionField, GeometryField, LineStringField, MultiLineStringField, MultiPointField, MultiPolygonField, PointField, PolygonField
K   django/contrib/gis/ FeedDoesNotExist
K   django/contrib/gis/forms/ GeometryField
R   django/contrib/gis/gdal/ c_void_p
R   django/contrib/gis/gdal/ SpatialReference
R   django/contrib/gis/gdal/ sys
R   django/contrib/gis/gdal/prototypes/ c_char, c_ubyte, date, re
R   django/contrib/gis/gdal/ OGRException, c_void_p, re
R   django/contrib/gis/gdal/tests/ os, os.path
K   django/contrib/gis/gdal/ CoordTransform, DataSource, Driver, Envelope, GDAL_VERSION, OGRException, OGRGeomType, OGRGeometry, OGRIndexError, SRSException, SpatialReference, check_err, gdal_full_version, gdal_release_date, gdal_version
K   django/contrib/gis/geometry/backend/ Geometry, GeometryException
R   django/contrib/gis/geos/ GEOSIndexError
R   django/contrib/gis/geos/ GEOM_PTR, GEOSIndexError
R   django/contrib/gis/geos/ c_size_t, re
K   django/contrib/gis/geos/ WKBWriter, WKTWriter
R   django/contrib/gis/geos/ GEOSIndexError
R   django/contrib/gis/geos/prototypes/ GEOS_PREPARE, PREPGEOM_PTR, c_uint
R   django/contrib/gis/geos/prototypes/ c_char_p
K   django/contrib/gis/geos/prototypes/ create_collection, create_cs, create_linearring, create_linestring, create_point, create_polygon, cs_clone, cs_getdims, cs_getordinate, cs_getsize, cs_getx, cs_gety, cs_getz, cs_setordinate, cs_setx, cs_sety, cs_setz, destroy_geom, from_hex, from_wkb, from_wkt, geom_clone, geos_contains, geos_crosses, geos_disjoint, geos_equals, geos_equalsexact, geos_get_srid, geos_hasz, geos_intersects, geos_isempty, geos_isring, geos_issimple, geos_isvalid, geos_normalize, geos_overlaps, geos_relatepattern, geos_set_srid, geos_touches, geos_type, geos_typeid, geos_within, get_cs, get_dims, get_extring, get_geomn, get_intring, get_nrings, get_num_coords, get_num_geoms, to_hex, to_wkb, to_wkt
R   django/contrib/gis/geos/tests/ sys
R   django/contrib/gis/geos/tests/ copy
R   django/contrib/gis/geos/tests/ ctypes
K   django/contrib/gis/geos/ GEOSException, GEOSGeometry, GEOSIndexError, GEOS_PREPARE, GeometryCollection, LineString, LinearRing, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon, WKBReader, WKBWriter, WKTReader, WKTWriter, fromfile, fromstr, geos_version, geos_version_info, hex_regex, wkt_regex
R   django/contrib/gis/management/commands/ CommandError, make_option
R   django/contrib/gis/management/commands/ sys
R   django/contrib/gis/maps/google/ GIcon, geos
R   django/contrib/gis/maps/google/ cos
K   django/contrib/gis/maps/google/ GEvent, GIcon, GMarker, GPolygon, GPolyline, GoogleMap, GoogleMapSet, GoogleZoom
K   django/contrib/gis/sitemaps/ GeoRSSSitemap, KMLSitemap, KMZSitemap
R   django/contrib/gis/tests/distapp/ Decimal, Point, os
R   django/contrib/gis/tests/geoapp/ Country, mysql
K   django/contrib/gis/tests/geoapp/ GeoFeedTest, GeoRegressionTests, GeoSitemapTest
R   django/contrib/gis/tests/geoapp/ Distance
R   django/contrib/gis/tests/geoapp/ no_oracle, no_postgis, os
R   django/contrib/gis/tests/geogapp/ A
R   django/contrib/gis/tests/layermap/ OGRException
R   django/contrib/gis/tests/ mysql
R   django/contrib/gis/utils/ date, datetime
R   django/contrib/gis/utils/ OFTTime
K   django/contrib/gis/utils/ GeoIP, GeoIPException, LayerMapError, LayerMapping, add_postgis_srs, add_srs_entry, mapping, ogrinfo, ogrinspect, precision_wkt, sample
R   django/contrib/localflavor/ar/ smart_unicode
R   django/contrib/localflavor/au/ settings
R   django/contrib/localflavor/be/ EMPTY_VALUES, ValidationError, re
R   django/contrib/localflavor/in_/ re
R   django/contrib/localflavor/jp/ ValidationError
R   django/contrib/localflavor/kw/ RegexField
R   django/contrib/localflavor/pt/ Select
R   django/contrib/localflavor/ro/ re
R   django/contrib/localflavor/ru/ CharField, EMPTY_VALUES, ValidationError
R   django/contrib/localflavor/se/ re
R   django/contrib/localflavor/us/ settings
R   django/contrib/localflavor/uy/ re
R   django/contrib/messages/ lazy, memoize
R   django/contrib/messages/storage/ constants
R   django/contrib/messages/tests/ warnings
R   django/contrib/messages/tests/ redirect, render_to_response
K   django/contrib/messages/tests/ CookieTest, FallbackTest, MiddlewareTest, SessionTest
R   django/contrib/sessions/backends/ sys
R   django/contrib/sessions/backends/ settings
R   django/contrib/sessions/ base64, pickle
R   django/contrib/sitemaps/ get_current_site
R   django/core/cache/backends/ settings
R   django/core/cache/backends/ importlib
K   django/core/cache/ BaseCache, CacheKeyWarning
K   django/core/files/ File
R   django/core/handlers/ pformat, smart_str
K   django/core/handlers/ settings
R   django/core/handlers/ pformat
K   django/core/handlers/ settings
K   django/core/mail/ BadHeaderError, CachedDnsName, DEFAULT_ATTACHMENT_MIME_TYPE, DNS_NAME, SafeMIMEMultipart, SafeMIMEText, _SMTPConnection, forbid_multi_line_headers, make_msgid
R   django/core/management/commands/ settings
K   django/core/management/commands/ user
K   django/core/management/ Image, settings
R   django/core/serializers/ datetime_safe, smart_str
K   django/core/serializers/ yaml
K   django/core/servers/ FileWrapper
K   django/core/servers/ flup
R   django/db/backends/postgresql_psycopg2/ re
K   django/db/backends/ decimal
K   django/db/models/ django.db.models.manager
R   django/db/models/ OneToOneRel, types
R   django/db/models/ GET_ITERATOR_CHUNK_SIZE
R   django/db/models/fields/ ContentFile, UploadedFile, _, cache, curry, get_image_dimensions, settings
R   django/db/models/fields/ settings, transaction, ugettext, ungettext
R   django/db/models/ imp
R   django/db/models/ settings
R   django/db/models/ Aggregate, DateField, izip, signals
R   django/db/models/ SortedDict
R   django/db/models/sql/ Model, connections
K   django/db/models/sql/ InvalidQuery, select_related_descend
R   django/db/models/sql/ SQLEvaluator, connections
R   django/db/models/sql/ QueryWrapper
K   django/db/models/sql/ AND, EmptyResultSet, OR
K   django/db/models/ CASCADE, DO_NOTHING, F, FileField, ForeignKey, ImageField, ImproperlyConfigured, Manager, ManyToManyField, ManyToManyRel, ManyToOneRel, Model, ObjectDoesNotExist, OneToOneField, OneToOneRel, PROTECT, ProtectedError, Q, SET, SET_DEFAULT, SET_NULL, SubfieldBase, connection, get_app, get_apps, get_model, get_models, register_models, settings, signals
R   django/db/ settings, sys
K   django/db/ IntegrityError
K   django/dispatch/ Signal, receiver
R   django/forms/extras/ time
R   django/forms/ EMPTY_VALUES, lazy, warnings
K   django/forms/ ValidationError
K   django/forms/ ValidationError
R   django/middleware/ MiddlewareNotUsed
K   django/template/ ContextPopException, RequestContext
R   django/template/ Promise, imp
R   django/template/ HttpRequest
R   django/template/ settings
R   django/template/ Context, Variable
R   django/template/loaders/ ImproperlyConfigured, import_module
R   django/template/ Context, TemplateDoesNotExist, Variable
R   django/template/ operator
K   django/template/ ALLOWED_VARIABLE_CHARS, BLOCK_TAG_END, BLOCK_TAG_START, COMMENT_TAG_END, COMMENT_TAG_START, Context, ContextPopException, FILTER_ARGUMENT_SEPARATOR, FILTER_SEPARATOR, FilterExpression, InvalidTemplateLibrary, Lexer, Library, Node, NodeList, Origin, Parser, RequestContext, SINGLE_BRACE_END, SINGLE_BRACE_START, StringOrigin, TOKEN_BLOCK, TOKEN_COMMENT, TOKEN_TEXT, TOKEN_VAR, TRANSLATOR_COMMENT_MARK, Template, TemplateDoesNotExist, TemplateEncodingError, TemplateSyntaxError, TextNode, Token, TokenParser, UNKNOWN_SOURCE, VARIABLE_ATTRIBUTE_SEPARATOR, VARIABLE_TAG_END, VARIABLE_TAG_START, Variable, VariableDoesNotExist, VariableNode, add_to_builtins, builtins, compile_string, constant_string, filter_raw_string, filter_re, generic_tag_compiler, get_library, get_templatetags_modules, get_text_list, import_library, libraries, resolve_variable, tag_re, unescape_string_literal
R   django/templatetags/ force_unicode
R   django/templatetags/ Node, Template, include_is_allowed, settings, smart_str
R   django/templatetags/ VariableNode, force_unicode
R   django/templatetags/ settings
R   django/test/ transaction, urlunparse
R   django/test/ UserSettingsHolder
R   django/test/ locmem, os, sys, time
K   django/test/ Approximate, Client, RequestFactory, TestCase, TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature
K   django/utils/ threading
R   django/utils/ HttpRequest
R   django/utils/ update_wrapper
K   django/utils/ dictConfig
R   django/utils/ sys
R   django/utils/ time
R   django/utils/translation/ warnings
R   django/utils/translation/ warnings
R   django/utils/unittest/ wraps
K   django/utils/unittest/ BaseTestSuite, FunctionTestCase, SkipTest, TestCase, TestLoader, TestProgram, TestResult, TestSuite, TextTestRunner, collector, defaultTestLoader, expectedFailure, findTestCases, getTestCaseNames, installHandler, main, main_, makeSuite, registerResult, removeHandler, removeResult, skip, skipIf, skipUnless
R   django/utils/ os.path
R   django/views/ pformat
R   django/views/decorators/ timedelta
R   django/views/generic/ RequestContext, loader
R   django/views/generic/ re
R   django/views/generic/ re
K   django/views/generic/ ArchiveIndexView, CreateView, DateDetailView, DayArchiveView, DeleteView, DetailView, FormView, ListView, MonthArchiveView, RedirectView, TemplateView, TodayArchiveView, UpdateView, View, WeekArchiveView, YearArchiveView

R   tests/modeltests/basic/ DEFAULT_DB_ALIAS, connection
R   tests/modeltests/basic/ DEFAULT_DB_ALIAS, connection, models
R   tests/modeltests/custom_pk/ DEFAULT_DB_ALIAS, IntegrityError, settings, transaction
R   tests/modeltests/custom_pk/ DEFAULT_DB_ALIAS, settings
R   tests/modeltests/delete/ IntegrityError
K   tests/modeltests/delete/ U
R   tests/modeltests/field_subclassing/ FieldError
R   tests/modeltests/field_subclassing/ Small
R   tests/modeltests/files/ ContentFile
R   tests/modeltests/files/ sys
R   tests/modeltests/fixtures/ DEFAULT_DB_ALIAS, settings
R   tests/modeltests/fixtures/ Blog, Category, DEFAULT_DB_ALIAS, Person, settings, sys
R   tests/modeltests/fixtures_model_package/models/ settings
R   tests/modeltests/force_insert_update/ IntegrityError, transaction
R   tests/modeltests/get_object_or_404/ Http404, get_list_or_404, get_object_or_404
R   tests/modeltests/get_or_create/ IntegrityError
R   tests/modeltests/lookup/ DEFAULT_DB_ALIAS, connection, settings
R   tests/modeltests/lookup/ connection
R   tests/modeltests/m2m_through/ TestNoDefaultsOrNulls
K   tests/modeltests/model_forms/ Image, _imaging
R   tests/modeltests/model_forms/ os
R   tests/modeltests/model_formsets/ Editor
K   tests/modeltests/model_package/models/ Article, Publication
R   tests/modeltests/mutually_referential/ Child
R   tests/modeltests/one_to_one/ IntegrityError, transaction
R   tests/modeltests/pagination/ attrgetter
R   tests/modeltests/proxy_models/ ContentType
R   tests/modeltests/proxy_model_inheritance/ Settings
K   tests/modeltests/test_client/ Session
R   tests/modeltests/transactions/ DEFAULT_DB_ALIAS
R   tests/modeltests/transactions/ DEFAULT_DB_ALIAS, settings, sys
R   tests/modeltests/unmanaged_models/ Unmanaged1
K   tests/modeltests/update/ C
R   tests/modeltests/validation/ TestCase
R   tests/modeltests/validation/ CustomMessagesTest, GetUniqueCheckTests, PerformUniqueChecksTest, TestModelsWithValidators
R   tests/modeltests/validation/ TestCase

R   tests/regressiontests/admin_filters/ with_statement
K   tests/regressiontests/admin_scripts/broken_app/ modelz
K   tests/regressiontests/admin_scripts/complex_app/models/ foo
K   tests/regressiontests/admin_scripts/complex_app/models/ Bar, Foo
K   tests/regressiontests/admin_scripts/simple_app/ Bar
K   tests/regressiontests/admin_views/ PersonAdmin, admin
R   tests/regressiontests/bash_completion/management/commands/ OptionParser, os, sys
R   tests/regressiontests/comment_tests/tests/ CT, CommentForm, Site
R   tests/regressiontests/comment_tests/tests/ get_warnings_state, restore_warnings_state, warnings
R   tests/regressiontests/comment_tests/tests/ Comment
R   tests/regressiontests/csrf_tests/ warnings
R   tests/regressiontests/datatypes/ DEFAULT_DB_ALIAS, settings
R   tests/regressiontests/defer_regress/ ContentType, connection, settings
R   tests/regressiontests/defer_regress/ connection, settings
R   tests/regressiontests/delete_regress/ Contact, connection
R   tests/regressiontests/expressions_regress/ models, settings
R   tests/regressiontests/file_storage/ File, _imaging
R   tests/regressiontests/fixtures_regress/ DEFAULT_DB_ALIAS, connection, settings
R   tests/regressiontests/fixtures_regress/ sys
R   tests/regressiontests/forms/localflavor/ ValidationError
K   tests/regressiontests/forms/ ARLocalFlavorTests, ATLocalFlavorTests, AULocalFlavorTests, AssertFieldOutputTests, BELocalFlavorTests, BRLocalFlavorTests, CALocalFlavorTests, CHLocalFlavorTests, CLLocalFlavorTests, CNLocalFlavorTests, CZLocalFlavorTests, DELocalFlavorTests, ESLocalFlavorTests, FILocalFlavorTests, FRLocalFlavorTests, GBLocalFlavorTests, GenericLocalFlavorTests, HRLocalFlavorTests, IDLocalFlavorTests, IELocalFlavorTests, ILLocalFlavorTests, ISLocalFlavorTests, ITLocalFlavorTests, JPLocalFlavorTests, KWLocalFlavorTests, NLLocalFlavorTests, PLLocalFlavorTests, PTLocalFlavorTests, ROLocalFlavorTests, RULocalFlavorTests, SELocalFlavorTests, SKLocalFlavorTests, TRLocalFlavorTests, USLocalFlavorTests, UYLocalFlavorTests, ZALocalFlavorTests
R   tests/regressiontests/forms/tests/ RadioFieldRenderer, time
R   tests/regressiontests/forms/tests/ Decimal, re, time
R   tests/regressiontests/forms/tests/ ChoiceModel
R   tests/regressiontests/forms/tests/ Decimal, re, time
K   tests/regressiontests/forms/tests/ ARLocalFlavorTests, ATLocalFlavorTests, AULocalFlavorTests, AssertFieldOutputTests, BELocalFlavorTests, BRLocalFlavorTests, CALocalFlavorTests, CHLocalFlavorTests, CLLocalFlavorTests, CNLocalFlavorTests, CZLocalFlavorTests, DELocalFlavorTests, ESLocalFlavorTests, FILocalFlavorTests, FRLocalFlavorTests, FieldsTests, GBLocalFlavorTests, GenericLocalFlavorTests, HRLocalFlavorTests, IDLocalFlavorTests, IELocalFlavorTests, ILLocalFlavorTests, ISLocalFlavorTests, ITLocalFlavorTests, JPLocalFlavorTests, KWLocalFlavorTests, NLLocalFlavorTests, PLLocalFlavorTests, PTLocalFlavorTests, ROLocalFlavorTests, RULocalFlavorTests, SELocalFlavorTests, SKLocalFlavorTests, TRLocalFlavorTests, TestFieldWithValidators, USLocalFlavorTests, UYLocalFlavorTests, ZALocalFlavorTests
R   tests/regressiontests/generic_relations_regress/ ContentType
R   tests/regressiontests/generic_views/ simplejson
R   tests/regressiontests/generic_views/ random
R   tests/regressiontests/generic_views/ CustomPaginator
K   tests/regressiontests/generic_views/ ArchiveIndexViewTests, CreateViewTests, DateDetailViewTests, DayArchiveViewTests, DeleteViewTests, DetailViewTest, ListViewTests, ModelFormMixinTests, MonthArchiveViewTests, RedirectViewTest, TemplateViewTest, UpdateViewTests, ViewTest, WeekArchiveViewTests, YearArchiveViewTests
R   tests/regressiontests/i18n/ template
K   tests/regressiontests/i18n/ DeprecationWarningTests
R   tests/regressiontests/i18n/ sys
R   tests/regressiontests/introspection/ DEFAULT_DB_ALIAS, settings
R   tests/regressiontests/localflavor/ TestCase, unittest
R   tests/regressiontests/m2m_through_regress/ datetime, management
K   tests/regressiontests/many_to_one_regress/ Second
R   tests/regressiontests/max_lengths/ DatabaseError
R   tests/regressiontests/middleware_exceptions/ models
R   tests/regressiontests/modeladmin/ date
R   tests/regressiontests/model_fields/ ContentFile
K   tests/regressiontests/model_fields/ _imaging
K   tests/regressiontests/model_fields/ FieldFile, ImageFieldDimensionsFirstTests, ImageFieldNoDimensionsTests, ImageFieldOneDimensionTests, ImageFieldTests, ImageFieldTwoDimensionsTests, ImageFieldUsingFileTests, TwoImageFieldTests, forms
R   tests/regressiontests/multiple_database/ settings
K   tests/regressiontests/multiple_database/ Article, article_using
R   tests/regressiontests/multiple_database/ ConnectionRouter, sys
R   tests/regressiontests/select_related_onetoone/ db, settings
R   tests/regressiontests/serializers_regress/ DEFAULT_DB_ALIAS, management, settings, transaction
R   tests/regressiontests/settings_tests/ skipIf, sys
R   tests/regressiontests/signals_regress/ StringIO, sys
R   tests/regressiontests/syndication/ datetime, warnings
R   tests/regressiontests/templates/ with_statement
R   tests/regressiontests/templates/ get_warnings_state, restore_warnings_state, warnings
R   tests/regressiontests/templates/ RequestContext
R   tests/regressiontests/templates/ Literal
K   tests/regressiontests/templates/templatetags/ Xtemplate
K   tests/regressiontests/templates/ ContextTests, CustomFilterTests, CustomTagTests, LocalTimezone, NodelistTest, ParserTests, UnicodeTests, _
R   tests/regressiontests/test_utils/ skipIfDBFeature, sys
R   tests/regressiontests/urlpatterns_reverse/ set_urlconf
K   tests/regressiontests/urlpatterns_reverse/ urlconf_inner
R   tests/regressiontests/utils/ difflib
K   tests/regressiontests/utils/ types
K   tests/regressiontests/utils/test_module/ a_package_name_that_does_not_exist
R   tests/regressiontests/views/tests/ ImproperlyConfigured
R   tests/regressiontests/views/tests/ path, settings

Changed 5 years ago by Aymeric Augustin

Attachment: 16225.patch added

Changed 5 years ago by Jannis Leidel

Attachment: 16225.2.diff added

Updated patch for r16387.

comment:6 Changed 5 years ago by Alex Gaynor

Feedback I gave jezdez on IRC:

 [12:04 PM] <Alex_Gaynor> jezdez: o_O damn, 100 seconds, I literally don't beleive that, also spataliate change makes it uglies
 [12:05 PM] <Alex_Gaynor> should probably move the import out of hte function
 [12:10 PM] <Alex_Gaynor> jezdez: also probably shouldn't mess with django.utils.unittest

comment:7 Changed 5 years ago by Aymeric Augustin

Has patch: set
Patch needs improvement: set

This patch isn't difficult; it's a just long and painful to write and maintain. Written one month ago, it's already outdated (it doesn't apply to trunk).

I'm ready to update it and take into account Alex's comments. However, before I spend a few hours on this, I'd like to know that a core dev is going to take a look reasonably soon afterwards... Otherwise it's a complete waste of time... Just waiting for your "thumbs up" :)

comment:8 Changed 5 years ago by Jannis Leidel

I'm ready to review and commit this if you're working on the patch.

comment:9 Changed 5 years ago by Aymeric Augustin

OK — barring unexpected problems, I'll post a new patch tonight.

comment:10 Changed 5 years ago by Aymeric Augustin

Patch needs improvement: unset

I started from your last patch and edited it until it applied properly.

I moved all imports in django/contrib/gis/gdal/tests/ to the beginning of the file. I reverted the changes in django/utils/unittest. I didn't touch django/contrib/gis/db/backends/spatialite/, even if it's ugly, because fixing import * abuse is beyond the scope of this ticket. Let's open another ticket if you think it's important.

I re-checked for unused imports, applying the same methodology described in comment 5 above, and removed several imports that were used one month ago but no longer are.

I ran the test suite (under sqlite) to check for imports that were unused one month ago, but now are used. This happened at least as a consequence of

Finally I proof-read the whole patch.

Here's the detail of what I have changed since the first patch, with this new code:
K+ = I had removed it, you kept it, I didn't remove it again (because I was wrong the first time, or because I'm not sure)
R+ = I had removed it, you kept it, I removed it again because I'm really, really sure it's unused
You may want to check them specially.

R   django/contrib/admin/templatetags/ settings
R   django/contrib/admin/ settings
R   django/contrib/auth/ Context
R   django/contrib/auth/tests/ settings
R   django/contrib/formtools/wizard/tests/namedwizardtests/ os, settings
R   django/contrib/gis/admin/ settings
K+  django/contrib/gis/db/models/ GeomField
R+  django/contrib/gis/tests/geoapp/ os
R   django/contrib/sitemaps/ HttpResponse, smart_str
R   django/core/handlers/ socket
R   django/core/servers/ ImproperlyConfigured
K   django/db/backends/dummy/ decimal
K   django/db/backends/mysql/ decimal
R   django/db/models/fields/ is_valid_ipv6_address
K+  django/db/models/sql/ Model, connections
K+  django/forms/ EMPTY_VALUES
K+  django/utils/ update_wrapper
K   django/utils/unittest/ wraps

R   tests/modeltests/many_to_one/ FieldError
K+  tests/modeltests/validation/ CustomMessagesTest, GetUniqueCheckTests, PerformUniqueChecksTest, TestModelsWithValidators
R   tests/modeltests/validation/ connection, settings

K+  tests/regressiontests/file_storage/ _imaging
R   tests/regressiontests/file_uploads/ MultiPartParserError
R   tests/regressiontests/forms/localflavor/ warnings
R   tests/regressiontests/forms/tests/ settings
R   tests/regressiontests/i18n/patterns/urls/ include
R   tests/regressiontests/i18n/patterns/urls/ patterns
R   tests/regressiontests/i18n/patterns/urls/ include
K   tests/regressiontests/urlpatterns_reverse/ non_existent
K   tests/regressiontests/urlpatterns_reverse/ non_existent

Changed 5 years ago by Aymeric Augustin

Attachment: 16225.3.diff added

updated patch for r16529

comment:11 Changed 5 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

In [16539]:

Fixed #16225 -- Removed unused imports. Many thanks to Aymeric Augustin for the work on the patch and Alex for reviewing.

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