Skip to contentSkip to conversation

python: Use isinstance() instead of type()

PATCH In review James Carter 2 participants 3 messages Aug 3, 2023 – Aug 8, 2023 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 python: Use isinstance() instead of type()

CI testing fails while running flake8 on python scripts with the message "./python/semanage/seobject.py:250:16: E721 do not compare types, for exact checks use is / is not, for instance checks use isinstance()"

Use "isinstance(args, str)" instead of "type(args) == str"

---
 python/semanage/seobject.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
python/semanage/seobject.py +1 -1
index 361205d1..cc944ae2 100644
@@ -247,7 +247,7 @@ class semanageRecords:
         global handle
         if args:
             # legacy code - args was store originally
-            if type(args) == str:
+            if isinstance(args, str):
                 self.store = args
             else:
                 self.args = args
Signature · 1 line
2.41.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · James Carter

CI testing fails while running flake8 on python scripts with the message "./python/semanage/seobject.py:250:16: E721 do not compare types, for exact checks use is / is not, for instance checks use isinstance()"

Use "isinstance(args, str)" instead of "type(args) == str"

Quoted 19 lines
---
 python/semanage/seobject.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
python/semanage/seobject.py +1 -1
index 361205d1..cc944ae2 100644
@@ -247,7 +247,7 @@ class semanageRecords:
         global handle
         if args:
             # legacy code - args was store originally
-            if type(args) == str:
+            if isinstance(args, str):
                 self.store = args
             else:
                 self.args = args
Signature · 1 line
2.41.0
#2 lore raw
Quoted 7 lines · Petr Lautrbach
Quoted 5 lines · James Carter

CI testing fails while running flake8 on python scripts with the message "./python/semanage/seobject.py:250:16: E721 do not compare types, for exact checks use is / is not, for instance checks use isinstance()"

Quoted 5 lines
Quoted 3 lines

Use "isinstance(args, str)" instead of "type(args) == str"

This is merged now, thanks!

Quoted 20 lines
Quoted 20 lines
---
 python/semanage/seobject.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
python/semanage/seobject.py +1 -1
index 361205d1..cc944ae2 100644
@@ -247,7 +247,7 @@ class semanageRecords:
         global handle
         if args:
             # legacy code - args was store originally
-            if type(args) == str:
+            if isinstance(args, str):
                 self.store = args
             else:
                 self.args = args
Signature · 1 line
2.41.0