Skip to content

Commit

Permalink
Replace .__class__ with type()
Browse files Browse the repository at this point in the history
Using .__class__ was necessary to support Python 2 old style classes. In
Python 3, all classes are new style.
  • Loading branch information
jdufresne committed Dec 4, 2019
1 parent 44aa525 commit badaa43
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions taggit/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def relabel_aliases(self, change_map):
self.alias = change_map.get(self.alias, self.alias)

def clone(self):
return self.__class__(self.alias, self.col, self.content_types[:])
return type(self)(self.alias, self.col, self.content_types[:])


class _TaggableManager(models.Manager):
Expand All @@ -73,7 +73,7 @@ def get_prefetch_queryset(self, instances, queryset=None):
raise ValueError("Custom queryset can't be used for this lookup.")

instance = instances[0]
db = self._db or router.db_for_read(instance.__class__, instance=instance)
db = self._db or router.db_for_read(type(instance), instance=instance)

fieldname = (
"object_id"
Expand Down
6 changes: 3 additions & 3 deletions taggit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def save(self, *args, **kwargs):
pass
# Now try to find existing slugs with similar names
slugs = set(
self.__class__._default_manager.filter(
slug__startswith=self.slug
).values_list("slug", flat=True)
type(self)
._default_manager.filter(slug__startswith=self.slug)
.values_list("slug", flat=True)
)
i = 1
while True:
Expand Down
6 changes: 3 additions & 3 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def test_require_pk(self):
food_instance = self.food_model()
msg = (
"%s objects need to have a primary key value before you can access "
"their tags." % self.food_model().__class__.__name__
"their tags." % type(self.food_model()).__name__
)
with self.assertRaisesMessage(ValueError, msg):
food_instance.tags.all()
Expand Down Expand Up @@ -841,10 +841,10 @@ class TaggableManagerInitializationTestCase(TaggableManagerTestCase):
custom_manager_model = CustomManager

def test_default_manager(self):
self.assertEqual(self.food_model.tags.__class__, _TaggableManager)
self.assertIs(type(self.food_model.tags), _TaggableManager)

def test_custom_manager(self):
self.assertEqual(self.custom_manager_model.tags.__class__, CustomManager.Foo)
self.assertIs(type(self.custom_manager_model.tags), CustomManager.Foo)


class TaggableFormTestCase(BaseTaggingTestCase):
Expand Down

0 comments on commit badaa43

Please sign in to comment.