python: Convert type checks to isinstance checks.

Generated by autopep8 --aggressive, with the setup.cfg configuration
from #14532.  In general, an isinstance check may not be equivalent to
a type check because it includes subtypes; however, that’s usually
what you want.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2020-04-21 16:59:09 -07:00 committed by Anders Kaseorg
parent 1cf63eb5bf
commit 088f7ee5d6
4 changed files with 5 additions and 5 deletions

View File

@ -30,9 +30,9 @@ def set_bot_storage(bot_profile: UserProfile, entries: List[Tuple[str, str]]) ->
storage_size_limit = settings.USER_STATE_SIZE_LIMIT
storage_size_difference = 0
for key, value in entries:
if type(key) is not str:
if not isinstance(key, str):
raise StateError("Key type is {}, but should be str.".format(type(key)))
if type(value) is not str:
if not isinstance(value, str):
raise StateError("Value type is {}, but should be str.".format(type(value)))
storage_size_difference += (len(key) + len(value)) - get_bot_storage_size(bot_profile, key)
new_storage_size = get_bot_storage_size(bot_profile) + storage_size_difference

View File

@ -148,7 +148,7 @@ cURL example.""".format(endpoint, method, param_name)
return ordered_ex_val_str # nocoverage
else:
example_value = param.get("example", DEFAULT_EXAMPLE[param_type])
if type(example_value) == bool:
if isinstance(example_value, bool):
example_value = str(example_value).lower()
if param["schema"].get("format", "") == "json":
example_value = json.dumps(example_value)

View File

@ -354,7 +354,7 @@ so maybe we shouldn't mark it as intentionally undocumented in the urls.
needs to be mapped to list."""
if sys.version_info < (3, 7): # nocoverage # python 3.5-3.6
if sys.version_info < (3, 6) and type(t) is type(Union): # python 3.5 has special consideration for Union
if sys.version_info < (3, 6) and isinstance(t, type(Union)): # python 3.5 has special consideration for Union
origin = Union
else:
origin = getattr(t, "__origin__", None)

View File

@ -1087,7 +1087,7 @@ def social_auth_associate_user(
user_profile = social_associate_user_helper(
backend, return_data, *args, **kwargs)
if type(user_profile) == HttpResponse:
if isinstance(user_profile, HttpResponse):
return user_profile
else:
return {'user_profile': user_profile,