Skip to content

Commit

Permalink
Replace type comparison with isinstance
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwpolska committed Aug 6, 2023
1 parent 31c67bb commit f7b2e69
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion v7/latex/latex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _read_extra_deps(self, post, lang):
if os.path.isfile(dep_path):
with io.open(dep_path, 'rb') as file:
result = json.loads(file.read().decode('utf-8'))
if type(result) == list and len(result) == 4:
if isinstance(result, list) and len(result) == 4:
return result
return ([], [], [], [])

Expand Down
6 changes: 3 additions & 3 deletions v7/latex/latex/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ def __flatten(self, block):
if isinstance(block, tree.Block):
while True:
if len(block.elements) == 1 and isinstance(block.elements[0], tree.Block):
if type(block) == tree.Block:
if isinstance(block, tree.Block):
block.elements[0].labels.extend(block.labels)
block = block.elements[0]
elif type(block.elements[0]) == tree.Block:
elif isinstance(block.elements[0], tree.Block):
block.labels.extend(block.elements[0].labels)
block.elements = block.elements[0].elements
else:
Expand Down Expand Up @@ -711,7 +711,7 @@ def add_to_current_word(part):

def __read_formula(self, delimiter):
start = self.tokens.current_indices()[0]
delimitedByEnvironmentEnd = (type(delimiter) == tuple)
delimitedByEnvironmentEnd = isinstance(delimiter, tuple)
while self.tokens.has_current():
stop = self.tokens.current_indices()[0]
token = self.tokens.current_type()
Expand Down
2 changes: 1 addition & 1 deletion v7/latex/latex/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def __init__(self, formula, args):
"""Initialize object."""
super(PSTricksPicture, self).__init__(formula)
self.args = args
assert type(self.args) == dict
assert isinstance(self.args, dict)

def recombine_as_text(self, reescape=True):
"""Recombine subtree as LaTeX source text."""
Expand Down
2 changes: 1 addition & 1 deletion v7/latex_formula_renderer/latex_formula_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def __read_database(self):
try:
with open(self.__get_database_file(), "rb") as file:
result = json.loads(file.read().decode('utf-8'))
if type(result) != list or len(result) != 2 or type(result[0]) != dict or type(result[1]) != list:
if not isinstance(result, list) or len(result) != 2 or not isinstance(result[0], dict) or not isinstance(result[1], list):
raise Exception("Read database invalid!")
result[1] = set(result[1])
return result
Expand Down
4 changes: 2 additions & 2 deletions v7/wordpress_compiler/wordpress/shortcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def shortcode_atts(pairs, atts):
# * @param array $pairs Entire list of supported attributes and their defaults.
# * @param array $atts User defined attributes in shortcode tag.
# * @return array Combined attribute list.
if type(atts) == str:
if isinstance(atts, str):
atts = {None: atts}
out = dict()
if type(pairs) == dict:
if isinstance(pairs, dict):
pairs = pairs.items()
for key, value in pairs:
if key in atts:
Expand Down
2 changes: 1 addition & 1 deletion v7/wordpress_compiler/wordpress/wordpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def _read_extra_deps(self, post, lang):
if os.path.isfile(dep_path):
with io.open(dep_path, 'rb') as file:
result = json.loads(file.read().decode('utf-8'))
if type(result) == list and len(result) == 4:
if isinstance(result, list) and len(result) == 4:
return result
return ([], [], [], [])

Expand Down

0 comments on commit f7b2e69

Please sign in to comment.