Skip to content

Commit

Permalink
apply C4 rule (#1953)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
njzjz and pre-commit-ci[bot] committed Jun 12, 2023
1 parent eb49d56 commit ffa8abc
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 25 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ select = [
"D", # pydocstyle
"I", # isort
"UP", # pyupgrade
"C4", # flake8-comprehensions
]
ignore = [
"E501", # line too long
Expand Down
20 changes: 9 additions & 11 deletions reacnetgenerator/_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,16 @@ def _connectmolecule(self, bond, level):
# int() because sometimes, the elements in bondlist are type numpy.int64 sometimes are int
# which cause the different bytes results from same bond-network.
mols, bondlists = dps(bond, level)
return list(
[
b"".join(
(
listtobytes(mol),
listtobytes([(int(i[0]), int(i[1])) for i in bondlist]),
listtobytes([int(i[2]) for i in bondlist]),
)
return [
b"".join(
(
listtobytes(mol),
listtobytes([(int(i[0]), int(i[1])) for i in bondlist]),
listtobytes([int(i[2]) for i in bondlist]),
)
for mol, bondlist in zip(mols, bondlists)
]
)
)
for mol, bondlist in zip(mols, bondlists)
]

def _writemoleculetempfile(self, d):
with WriteBuffer(tempfile.NamedTemporaryFile("wb", delete=False)) as f:
Expand Down
4 changes: 2 additions & 2 deletions reacnetgenerator/_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def _handlespecies(self, name):
species = [spec for spec in species if spec not in self.speciesfilter]

if self.showid:
showname = dict([(v, u) for u, v in enumerate(species, start=1)])
showname = {v: u for u, v in enumerate(species, start=1)}
else:
showname = dict([(u, u) for u in species])
showname = {u: u for u in species}
if species:
logger.info("Species are:")
for specname, n in showname.items():
Expand Down
2 changes: 1 addition & 1 deletion reacnetgenerator/_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,5 @@ def _printspecies(self):
d[t][name] += 1
for t in range(len(self.timestep)):
fw.append(f"Timestep {self.timestep[t]}:")
fw.extend(map(lambda item: f" {item[0]} {item[1]}", d[t].items()))
fw.extend(f" {item[0]} {item[1]}" for item in d[t].items())
fw.append("\n")
12 changes: 5 additions & 7 deletions reacnetgenerator/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,10 @@ def collect(self):
self.allmoleculeroute = self._printatomroute(atomeach)
if self.split > 1:
splittime = np.array_split(np.arange(self.step), self.split)
self.splitmoleculeroute = list(
[
self._printatomroute(atomeach[:, st], timeaxis=i)
for i, st in enumerate(splittime)
]
)
self.splitmoleculeroute = [
self._printatomroute(atomeach[:, st], timeaxis=i)
for i, st in enumerate(splittime)
]
self.returnkeys()
ReactionsFinder(self.rng).findreactions(atomeach.T, conflict.T)

Expand Down Expand Up @@ -341,7 +339,7 @@ def __init__(self, cmp, atoms, bonds):
self.graph = self._makemoleculegraph()
counter = Counter(self._atomnames)
self.name = "".join(
map(lambda atomname: f"{atomname}{counter[atomname]}", cmp.atomname)
f"{atomname}{counter[atomname]}" for atomname in cmp.atomname
)
self._smiles = None
self._convertSMILES = cmp.convertSMILES
Expand Down
6 changes: 3 additions & 3 deletions reacnetgenerator/_reachtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def _re(self, smi):
def _handlereaction(self, line):
sx = line.split()
left, right = sx[1].split("->")
left = list([self._re(spec) for spec in left.split("+")])
right = list([self._re(spec) for spec in right.split("+")])
left = [self._re(spec) for spec in left.split("+")]
right = [self._re(spec) for spec in right.split("+")]
num = int(sx[0])
return left, right, num

Expand Down Expand Up @@ -145,7 +145,7 @@ def _readspecies(self, reaction, timeaxis=None):
if timeaxis is None:
self._svgspecs.add(spec)
# return list of dict
return list([{"s": spec, "i": i} for i, spec in enumerate(specs, 1)])
return [{"s": spec, "i": i} for i, spec in enumerate(specs, 1)]

def _readdata(self):
self._reaction = [self._readreaction()]
Expand Down
2 changes: 1 addition & 1 deletion reacnetgenerator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def listtostirng(
if isinstance(l, str):
return l
if isinstance(l, (list, tuple, np.ndarray)):
return sep[0].join(map(lambda x: listtostirng(x, sep[1:]), l))
return sep[0].join(listtostirng(x, sep[1:]) for x in l)
return str(l)


Expand Down

0 comments on commit ffa8abc

Please sign in to comment.