From 4bb6bf186dda77d38914bc6a12033e766b68eebc Mon Sep 17 00:00:00 2001 From: Nicolas Forstner Date: Sun, 20 Apr 2025 14:28:32 +0100 Subject: [PATCH] Fix use of is and is not vs. == --- polymorphic/base.py | 2 +- polymorphic/query.py | 2 +- polymorphic/showfields.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/polymorphic/base.py b/polymorphic/base.py index b1f40253..bb648064 100644 --- a/polymorphic/base.py +++ b/polymorphic/base.py @@ -73,7 +73,7 @@ def __new__(self, model_name, bases, attrs, **kwargs): # determine the name of the primary key field and store it into the class variable # polymorphic_primary_key_name (it is needed by query.py) for f in new_class._meta.fields: - if f.primary_key and type(f) != models.OneToOneField: + if f.primary_key and type(f) is not models.OneToOneField: new_class.polymorphic_primary_key_name = f.name break diff --git a/polymorphic/query.py b/polymorphic/query.py index ba67529e..8a139cee 100644 --- a/polymorphic/query.py +++ b/polymorphic/query.py @@ -267,7 +267,7 @@ def tree_node_test___lookup(my_model, node): for i in range(len(node.children)): child = node.children[i] - if type(child) == tuple: + if type(child) is tuple: # this Q object child is a tuple => a kwarg like Q( instance_of=ModelB ) assert "___" not in child[0], ___lookup_assert_msg else: diff --git a/polymorphic/showfields.py b/polymorphic/showfields.py index 1339fc49..e894c70b 100644 --- a/polymorphic/showfields.py +++ b/polymorphic/showfields.py @@ -62,7 +62,7 @@ def _showfields_add_regular_fields(self, parts): out = field.name # if this is the standard primary key named "id", print it as we did with older versions of django_polymorphic - if field.primary_key and field.name == "id" and type(field) == models.AutoField: + if field.primary_key and field.name == "id" and type(field) is models.AutoField: out += f" {getattr(self, field.name)}" # otherwise, display it just like all other fields (with correct type, shortened content etc.)