diff mbox series

python: Use isinstance() instead of type()

Message ID 20230803134024.20849-1-jwcart2@gmail.com (mailing list archive)
State Accepted
Commit f6dc6acfa007
Delegated to: Petr Lautrbach
Headers show
Series python: Use isinstance() instead of type() | expand

Commit Message

James Carter Aug. 3, 2023, 1:40 p.m. UTC
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"

Signed-off-by: James Carter <jwcart2@gmail.com>
---
 python/semanage/seobject.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Petr Lautrbach Aug. 8, 2023, 10:30 a.m. UTC | #1
James Carter <jwcart2@gmail.com> writes:

> 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"
>
> Signed-off-by: James Carter <jwcart2@gmail.com>

Acked-by: Petr Lautrbach <lautrbach@redhat.com>


> ---
>  python/semanage/seobject.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
> index 361205d1..cc944ae2 100644
> --- a/python/semanage/seobject.py
> +++ b/python/semanage/seobject.py
> @@ -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
> -- 
> 2.41.0
Petr Lautrbach Aug. 8, 2023, 11:01 a.m. UTC | #2
Petr Lautrbach <plautrba@redhat.com> writes:

> James Carter <jwcart2@gmail.com> writes:
>
>> 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"
>>
>> Signed-off-by: James Carter <jwcart2@gmail.com>
>
> Acked-by: Petr Lautrbach <lautrbach@redhat.com>

This is merged now, thanks!


>
>> ---
>>  python/semanage/seobject.py | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
>> index 361205d1..cc944ae2 100644
>> --- a/python/semanage/seobject.py
>> +++ b/python/semanage/seobject.py
>> @@ -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
>> -- 
>> 2.41.0
diff mbox series

Patch

diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
index 361205d1..cc944ae2 100644
--- a/python/semanage/seobject.py
+++ b/python/semanage/seobject.py
@@ -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