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):
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()
}
if mapping is not None
@@ -320,7 +320,7 @@ class AttributesHandler(Mapping[str, _TextHandlerType]):
if kwargs:
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()
}
)
+1 -1
View File
@@ -22,7 +22,7 @@ class StorageSystemMixin(ABC):
@lru_cache(64, typed=True)
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
try:
+1 -1
View File
@@ -240,7 +240,7 @@ class ResponseFactory:
return Response(
url=response.url,
content=response.content
if type(response.content) is bytes
if isinstance(response.content, bytes)
else response.content.encode(),
status=response.status_code,
reason=response.reason,
+1 -1
View File
@@ -216,7 +216,7 @@ class BaseFetcher:
storage_args=cls.storage_args,
)
if cls.adaptive_domain:
if type(cls.adaptive_domain) is not str:
if not isinstance(cls.adaptive_domain, str):
log.warning(
'[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!
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():