sourcery
sourcery copied to clipboard
Refactor using with block misses second open()/close() set
Issue description or question
In the following function, Sourcery only suggests to refactor the outfile open()/close() set to a with block, but doesn't make any suggestions about the infile open()/close():
def in_out(self, infile, outfile):
infile = open(infile, "rb")
outfile = open(outfile, "w")
for l in infile.readlines():
outfile.write(l)
infile.close()
outfile.close()
However, they can both be combined into a single with block:
def in_out(self, infile, outfile):
with open(infile, "rb") as infile, open(outfile, "w") as outfile:
for l in infile.readlines():
outfile.write(l)
Sourcery Version
v0.8.7
Code editor or IDE name and version
VS Code 1.52.1
OS name and
Ubuntu Linux 20.04.1
Yeah would be nice if it spotted both - it does if the closes are swapped.