From 1df1378f9e6e71588f45624c4ddf9e5d37cc875a Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 26 Sep 2010 21:36:22 +0000 Subject: [PATCH] Fixed #13827 -- Cleaned up a few unnecessary function calls. git-svn-id: http://code.djangoproject.com/svn/django/trunk@13876 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/conf/__init__.py | 2 +- django/contrib/admin/validation.py | 2 +- django/contrib/auth/__init__.py | 9 +++------ django/contrib/gis/sitemaps/views.py | 2 +- django/core/cache/__init__.py | 2 +- django/db/models/base.py | 2 +- django/db/models/options.py | 6 +++--- django/db/models/query_utils.py | 5 ++--- django/forms/forms.py | 2 +- django/test/simple.py | 2 +- .../regressiontests/comment_tests/tests/app_api_tests.py | 2 +- 11 files changed, 16 insertions(+), 20 deletions(-) diff --git a/django/conf/__init__.py b/django/conf/__init__.py index bda0ef3691..20d1aa1c86 100644 --- a/django/conf/__init__.py +++ b/django/conf/__init__.py @@ -102,7 +102,7 @@ class Settings(object): new_installed_apps.append(app) self.INSTALLED_APPS = new_installed_apps - if hasattr(time, 'tzset') and getattr(self, 'TIME_ZONE'): + if hasattr(time, 'tzset') and self.TIME_ZONE: # When we can, attempt to validate the timezone. If we can't find # this file, no check happens and it's harmless. zoneinfo_root = '/usr/share/zoneinfo' diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py index bee28912af..8d7a8c9d74 100644 --- a/django/contrib/admin/validation.py +++ b/django/contrib/admin/validation.py @@ -170,7 +170,7 @@ def validate_inline(cls, parent, parent_model): fk = _get_foreign_key(parent_model, cls.model, fk_name=cls.fk_name, can_fail=True) # extra = 3 - if not isinstance(getattr(cls, 'extra'), int): + if not isinstance(cls.extra, int): raise ImproperlyConfigured("'%s.extra' should be a integer." % cls.__name__) diff --git a/django/contrib/auth/__init__.py b/django/contrib/auth/__init__.py index 169ae01070..a184aeada8 100644 --- a/django/contrib/auth/__init__.py +++ b/django/contrib/auth/__init__.py @@ -20,15 +20,12 @@ def load_backend(path): cls = getattr(mod, attr) except AttributeError: raise ImproperlyConfigured('Module "%s" does not define a "%s" authentication backend' % (module, attr)) - try: - getattr(cls, 'supports_object_permissions') - except AttributeError: + if not hasattr(cls, "supports_object_permissions"): warn("Authentication backends without a `supports_object_permissions` attribute are deprecated. Please define it in %s." % cls, PendingDeprecationWarning) cls.supports_object_permissions = False - try: - getattr(cls, 'supports_anonymous_user') - except AttributeError: + + if not hasattr(cls, 'supports_anonymous_user'): warn("Authentication backends without a `supports_anonymous_user` attribute are deprecated. Please define it in %s." % cls, PendingDeprecationWarning) cls.supports_anonymous_user = False diff --git a/django/contrib/gis/sitemaps/views.py b/django/contrib/gis/sitemaps/views.py index f3c1da24ed..152edc94ae 100644 --- a/django/contrib/gis/sitemaps/views.py +++ b/django/contrib/gis/sitemaps/views.py @@ -93,7 +93,7 @@ def kml(request, label, model, field_name=None, compress=False, using=DEFAULT_DB else: qs = klass._default_manager.using(using).all() for mod in qs: - setattr(mod, 'kml', getattr(mod, field_name).kml) + mod.kml = getattr(mod, field_name).kml) placemarks.append(mod) # Getting the render function and rendering to the correct. diff --git a/django/core/cache/__init__.py b/django/core/cache/__init__.py index 680f724f94..e49590b328 100644 --- a/django/core/cache/__init__.py +++ b/django/core/cache/__init__.py @@ -63,7 +63,7 @@ def get_cache(backend_uri): else: name = scheme module = importlib.import_module(name) - return getattr(module, 'CacheClass')(host, params) + return module.CacheClass(host, params) cache = get_cache(settings.CACHE_BACKEND) diff --git a/django/db/models/base.py b/django/db/models/base.py index b3deda13d4..67797b5164 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -508,7 +508,7 @@ class Model(object): # autopopulate the _order field field = meta.order_with_respect_to order_value = manager.using(using).filter(**{field.name: getattr(self, field.attname)}).count() - setattr(self, '_order', order_value) + self._order = order_value if not pk_set: if force_update: diff --git a/django/db/models/options.py b/django/db/models/options.py index 5d84ab6472..5cf911dc98 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -79,14 +79,14 @@ class Options(object): # unique_together can be either a tuple of tuples, or a single # tuple of two strings. Normalize it to a tuple of tuples, so that # calling code can uniformly expect that. - ut = meta_attrs.pop('unique_together', getattr(self, 'unique_together')) + ut = meta_attrs.pop('unique_together', self.unique_together) if ut and not isinstance(ut[0], (tuple, list)): ut = (ut,) - setattr(self, 'unique_together', ut) + self.unique_together = ut # verbose_name_plural is a special case because it uses a 's' # by default. - setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', string_concat(self.verbose_name, 's'))) + self.verbose_name_plural = meta_attrs.pop('verbose_name_plural', string_concat(self.verbose_name, 's')) # Any leftover attributes must be invalid. if meta_attrs != {}: diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py index 046749c135..8b32b964db 100644 --- a/django/db/models/query_utils.py +++ b/django/db/models/query_utils.py @@ -257,9 +257,8 @@ def deferred_class_factory(model, attrs): deferred attributes to a particular instance of the model. """ class Meta: - pass - setattr(Meta, "proxy", True) - setattr(Meta, "app_label", model._meta.app_label) + proxy = True + app_label = model._meta.app_label # The app_cache wants a unique name for each model, otherwise the new class # won't be created (we get an old one back). Therefore, we generate the diff --git a/django/forms/forms.py b/django/forms/forms.py index 7b2bc66fc7..13ef1a7682 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -268,7 +268,7 @@ class BaseForm(StrAndUnicode): self._clean_form() self._post_clean() if self._errors: - delattr(self, 'cleaned_data') + del self.cleaned_data def _clean_fields(self): for name, field in self.fields.items(): diff --git a/django/test/simple.py b/django/test/simple.py index 9013042e66..be5550f9bf 100644 --- a/django/test/simple.py +++ b/django/test/simple.py @@ -58,7 +58,7 @@ class DjangoTestRunner(unittest.TextTestRunner): func(test) return stoptest - setattr(result, 'stopTest', stoptest_override(result.stopTest)) + result.stopTest = stoptest_override(result.stopTest) return result def get_tests(app_module): diff --git a/tests/regressiontests/comment_tests/tests/app_api_tests.py b/tests/regressiontests/comment_tests/tests/app_api_tests.py index c4d9ebfef3..4015487e3b 100644 --- a/tests/regressiontests/comment_tests/tests/app_api_tests.py +++ b/tests/regressiontests/comment_tests/tests/app_api_tests.py @@ -41,7 +41,7 @@ class CustomCommentTest(CommentTestCase): del settings.INSTALLED_APPS[-1] settings.COMMENTS_APP = self.old_comments_app if settings.COMMENTS_APP is None: - delattr(settings._wrapped, 'COMMENTS_APP') + del settings._wrapped.COMMENTS_APP def testGetCommentApp(self): from regressiontests.comment_tests import custom_comments