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
+2 -2
View File
@@ -310,7 +310,7 @@ class AttributesHandler(Mapping[str, _TextHandlerType]):
def __init__(self, mapping=None, **kwargs): def __init__(self, mapping=None, **kwargs):
mapping = ( mapping = (
{ {
key: TextHandler(value) if type(value) is str else value key: TextHandler(value) if isinstance(value, str) else value
for key, value in mapping.items() for key, value in mapping.items()
} }
if mapping is not None if mapping is not None
@@ -320,7 +320,7 @@ class AttributesHandler(Mapping[str, _TextHandlerType]):
if kwargs: if kwargs:
mapping.update( mapping.update(
{ {
key: TextHandler(value) if type(value) is str else value key: TextHandler(value) if isinstance(value, str) else value
for key, value in kwargs.items() for key, value in kwargs.items()
} }
) )
+1 -1
View File
@@ -22,7 +22,7 @@ class StorageSystemMixin(ABC):
@lru_cache(64, typed=True) @lru_cache(64, typed=True)
def _get_base_url(self, default_value: str = "default") -> str: def _get_base_url(self, default_value: str = "default") -> str:
if not self.url or type(self.url) is not str: if not self.url or not isinstance(self.url, str):
return default_value return default_value
try: try:
+1 -1
View File
@@ -240,7 +240,7 @@ class ResponseFactory:
return Response( return Response(
url=response.url, url=response.url,
content=response.content content=response.content
if type(response.content) is bytes if isinstance(response.content, bytes)
else response.content.encode(), else response.content.encode(),
status=response.status_code, status=response.status_code,
reason=response.reason, reason=response.reason,
+1 -1
View File
@@ -216,7 +216,7 @@ class BaseFetcher:
storage_args=cls.storage_args, storage_args=cls.storage_args,
) )
if cls.adaptive_domain: if cls.adaptive_domain:
if type(cls.adaptive_domain) is not str: if not isinstance(cls.adaptive_domain, str):
log.warning( log.warning(
'[Ignored] The argument "adaptive_domain" must be of string type' '[Ignored] The argument "adaptive_domain" must be of string type'
) )
+10 -5
View File
@@ -734,11 +734,11 @@ class Selector(SelectorsGeneration):
# Brace yourself for a wonderful journey! # Brace yourself for a wonderful journey!
for arg in args: for arg in args:
if type(arg) is str: if isinstance(arg, str):
tags.add(arg) tags.add(arg)
elif type(arg) in [list, tuple, set]: elif type(arg) in (list, tuple, set):
if not all(map(lambda x: type(x) is str, arg)): if not all(map(lambda x: isinstance(x, str), arg)):
raise TypeError( raise TypeError(
"Nested Iterables are not accepted, only iterables of tag names are accepted" "Nested Iterables are not accepted, only iterables of tag names are accepted"
) )
@@ -746,7 +746,10 @@ class Selector(SelectorsGeneration):
elif isinstance(arg, dict): elif isinstance(arg, dict):
if not all( 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( raise TypeError(
"Nested dictionaries are not accepted, only string keys and string values are accepted" "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.' 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") raise TypeError("Only string values are accepted for arguments")
for attribute_name, value in kwargs.items(): for attribute_name, value in kwargs.items():