style: using isinstance function as the main way for type checking

This commit is contained in:
Karim shoair
2025-07-30 03:14:23 +03:00
parent ae9ccaec79
commit 5bb1266fa5
5 changed files with 15 additions and 10 deletions
+10 -5
View File
@@ -734,11 +734,11 @@ class Selector(SelectorsGeneration):
# Brace yourself for a wonderful journey!
for arg in args:
if type(arg) is str:
if isinstance(arg, str):
tags.add(arg)
elif type(arg) in [list, tuple, set]:
if not all(map(lambda x: type(x) is str, arg)):
elif type(arg) in (list, tuple, set):
if not all(map(lambda x: isinstance(x, str), arg)):
raise TypeError(
"Nested Iterables are not accepted, only iterables of tag names are accepted"
)
@@ -746,7 +746,10 @@ class Selector(SelectorsGeneration):
elif isinstance(arg, dict):
if not all(
[(type(k) is str and type(v) is str) for k, v in arg.items()]
[
(isinstance(k, str) and isinstance(v, str))
for k, v in arg.items()
]
):
raise TypeError(
"Nested dictionaries are not accepted, only string keys and string values are accepted"
@@ -769,7 +772,9 @@ class Selector(SelectorsGeneration):
f'Argument with type "{type(arg)}" is not accepted, please read the docs.'
)
if not all([(type(k) is str and type(v) is str) for k, v in kwargs.items()]):
if not all(
[(isinstance(k, str) and isinstance(v, str)) for k, v in kwargs.items()]
):
raise TypeError("Only string values are accepted for arguments")
for attribute_name, value in kwargs.items():