diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-04-26 13:30:48 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-04-26 13:30:48 +0000 |
| commit | 439cb4047fb583d08149f28e2ce66a8edfe0efa7 (patch) | |
| tree | 47ef30e70bf1d757f08b133d3aa47704db13c714 /django/db | |
| parent | 6c02565e4fb92c4cc3bfb45bcc89eb9aa299efdc (diff) | |
Fixed #4040 -- Changed uses of has_key() to "in". Slight performance
improvement and forward-compatible with future Python releases. Patch from Gary
Wilson.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5091 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/backends/mysql_old/base.py | 2 | ||||
| -rw-r--r-- | django/db/backends/postgresql/base.py | 2 | ||||
| -rw-r--r-- | django/db/backends/util.py | 2 | ||||
| -rw-r--r-- | django/db/models/fields/__init__.py | 2 | ||||
| -rw-r--r-- | django/db/models/fields/generic.py | 2 | ||||
| -rw-r--r-- | django/db/models/fields/related.py | 4 | ||||
| -rw-r--r-- | django/db/models/loading.py | 2 | ||||
| -rw-r--r-- | django/db/models/options.py | 4 | ||||
| -rw-r--r-- | django/db/transaction.py | 12 |
9 files changed, 16 insertions, 16 deletions
diff --git a/django/db/backends/mysql_old/base.py b/django/db/backends/mysql_old/base.py index 01eff22641..d56b8513f9 100644 --- a/django/db/backends/mysql_old/base.py +++ b/django/db/backends/mysql_old/base.py @@ -53,7 +53,7 @@ class MysqlDebugWrapper: raise Database.Warning, "%s: %s" % (w, self.cursor.fetchall()) def __getattr__(self, attr): - if self.__dict__.has_key(attr): + if attr in self.__dict__: return self.__dict__[attr] else: return getattr(self.cursor, attr) diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index bb52711191..dc0fbe3ab9 100644 --- a/django/db/backends/postgresql/base.py +++ b/django/db/backends/postgresql/base.py @@ -48,7 +48,7 @@ class UnicodeCursorWrapper(object): return self.cursor.executemany(sql, new_param_list) def __getattr__(self, attr): - if self.__dict__.has_key(attr): + if attr in self.__dict__: return self.__dict__[attr] else: return getattr(self.cursor, attr) diff --git a/django/db/backends/util.py b/django/db/backends/util.py index d8f86fef4f..d14a337ca2 100644 --- a/django/db/backends/util.py +++ b/django/db/backends/util.py @@ -33,7 +33,7 @@ class CursorDebugWrapper(object): }) def __getattr__(self, attr): - if self.__dict__.has_key(attr): + if attr in self.__dict__: return self.__dict__[attr] else: return getattr(self.cursor, attr) diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 466897ad86..91629cd679 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -779,7 +779,7 @@ class SlugField(Field): kwargs['maxlength'] = kwargs.get('maxlength', 50) kwargs.setdefault('validator_list', []).append(validators.isSlug) # Set db_index=True unless it's been set manually. - if not kwargs.has_key('db_index'): + if 'db_index' not in kwargs: kwargs['db_index'] = True Field.__init__(self, *args, **kwargs) diff --git a/django/db/models/fields/generic.py b/django/db/models/fields/generic.py index 480ee689c9..f995ab2044 100644 --- a/django/db/models/fields/generic.py +++ b/django/db/models/fields/generic.py @@ -37,7 +37,7 @@ class GenericForeignKey(object): def instance_pre_init(self, signal, sender, args, kwargs): # Handle initalizing an object with the generic FK instaed of # content-type/object-id fields. - if kwargs.has_key(self.name): + if self.name in kwargs: value = kwargs.pop(self.name) kwargs[self.ct_field] = self.get_content_type(value) kwargs[self.fk_field] = value._get_pk_val() diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index fad9c164c1..e8152f32e7 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -474,7 +474,7 @@ class ForeignKey(RelatedField, Field): to_field = to_field or to._meta.pk.name kwargs['verbose_name'] = kwargs.get('verbose_name', '') - if kwargs.has_key('edit_inline_type'): + if 'edit_inline_type' in kwargs: import warnings warnings.warn("edit_inline_type is deprecated. Use edit_inline instead.") kwargs['edit_inline'] = kwargs.pop('edit_inline_type') @@ -567,7 +567,7 @@ class OneToOneField(RelatedField, IntegerField): to_field = to_field or to._meta.pk.name kwargs['verbose_name'] = kwargs.get('verbose_name', '') - if kwargs.has_key('edit_inline_type'): + if 'edit_inline_type' in kwargs: import warnings warnings.warn("edit_inline_type is deprecated. Use edit_inline instead.") kwargs['edit_inline'] = kwargs.pop('edit_inline_type') diff --git a/django/db/models/loading.py b/django/db/models/loading.py index f4aff2438b..224f5e8451 100644 --- a/django/db/models/loading.py +++ b/django/db/models/loading.py @@ -103,7 +103,7 @@ def register_models(app_label, *models): # in the _app_models dictionary model_name = model._meta.object_name.lower() model_dict = _app_models.setdefault(app_label, {}) - if model_dict.has_key(model_name): + if model_name in model_dict: # The same model may be imported via different paths (e.g. # appname.models and project.appname.models). We use the source # filename as a means to detect identity. diff --git a/django/db/models/options.py b/django/db/models/options.py index 51cf0a019b..dd6c586ddd 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -140,7 +140,7 @@ class Options(object): def get_follow(self, override=None): follow = {} for f in self.fields + self.many_to_many + self.get_all_related_objects(): - if override and override.has_key(f.name): + if override and f.name in override: child_override = override[f.name] else: child_override = None @@ -182,7 +182,7 @@ class Options(object): # TODO: follow if not hasattr(self, '_field_types'): self._field_types = {} - if not self._field_types.has_key(field_type): + if field_type not in self._field_types: try: # First check self.fields. for f in self.fields: diff --git a/django/db/transaction.py b/django/db/transaction.py index 4a0658e1c3..bb90713525 100644 --- a/django/db/transaction.py +++ b/django/db/transaction.py @@ -46,12 +46,12 @@ def enter_transaction_management(): when no current block is running). """ thread_ident = thread.get_ident() - if state.has_key(thread_ident) and state[thread_ident]: + if thread_ident in state and state[thread_ident]: state[thread_ident].append(state[thread_ident][-1]) else: state[thread_ident] = [] state[thread_ident].append(settings.TRANSACTIONS_MANAGED) - if not dirty.has_key(thread_ident): + if thread_ident not in dirty: dirty[thread_ident] = False def leave_transaction_management(): @@ -61,7 +61,7 @@ def leave_transaction_management(): those from outside. (Commits are on connection level.) """ thread_ident = thread.get_ident() - if state.has_key(thread_ident) and state[thread_ident]: + if thread_ident in state and state[thread_ident]: del state[thread_ident][-1] else: raise TransactionManagementError("This code isn't under transaction management") @@ -84,7 +84,7 @@ def set_dirty(): changes waiting for commit. """ thread_ident = thread.get_ident() - if dirty.has_key(thread_ident): + if thread_ident in dirty: dirty[thread_ident] = True else: raise TransactionManagementError("This code isn't under transaction management") @@ -96,7 +96,7 @@ def set_clean(): should happen. """ thread_ident = thread.get_ident() - if dirty.has_key(thread_ident): + if thread_ident in dirty: dirty[thread_ident] = False else: raise TransactionManagementError("This code isn't under transaction management") @@ -106,7 +106,7 @@ def is_managed(): Checks whether the transaction manager is in manual or in auto state. """ thread_ident = thread.get_ident() - if state.has_key(thread_ident): + if thread_ident in state: if state[thread_ident]: return state[thread_ident][-1] return settings.TRANSACTIONS_MANAGED |
