Use union syntax for isinstance checks (UP038 rule in Ruff) (#2829)

This commit is contained in:
correctmost 2024-11-16 04:47:01 -05:00 committed by GitHub
parent b61b5c82fa
commit 44f4bc8612
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 4 deletions

View File

@ -70,9 +70,9 @@ def jsonify(obj: Any, safe: bool = True) -> Any:
# a dictionary representation of the object so that it can be
# processed by the json library.
return jsonify(obj.json(), safe)
if isinstance(obj, (datetime, date)):
if isinstance(obj, datetime | date):
return obj.isoformat()
if isinstance(obj, (list, set, tuple)):
if isinstance(obj, list | set | tuple):
return [jsonify(item, safe) for item in obj]
if isinstance(obj, pathlib.Path):
return str(obj)

View File

@ -131,7 +131,7 @@ class Selector:
def is_empty(self) -> bool:
if self.current_selection is None:
return True
elif isinstance(self.current_selection, (str, list, dict)) and len(self.current_selection) == 0:
elif isinstance(self.current_selection, str | list | dict) and len(self.current_selection) == 0:
return True
return False

View File

@ -103,7 +103,7 @@ class FormattedOutput:
if '!' in key:
value = '*' * len(value)
if isinstance(value, (int, float)) or (isinstance(value, str) and value.isnumeric()):
if isinstance(value, int | float) or (isinstance(value, str) and value.isnumeric()):
obj_data.append(unicode_rjust(str(value), width))
else:
obj_data.append(unicode_ljust(str(value), width))