Closed hechth closed 1 year ago
Hi!
I find that the decorator is necessary because it is used in multiple functions. It helps ensure unified behavior and reduces code duplication, improving reliability.
You can quite easily rewrite the main loop in save_as_mgf
such that the file_mode
argument is not used at all, eliminating the linting error and arguably optimizing the code:
# Convert matchms.Spectrum() into dictionaries for pyteomics
spectrum_dicts = (
{"m/z array": spectrum.peaks.mz,
"intensity array": spectrum.peaks.intensities,
"params": spectrum.metadata}
for spectrum in spectrums)
# Append all spectra to file
with open(filename, 'a') as out:
py_mgf.write(spectrum_dicts, out)
For more info and examples, see #109.
Thanks for the hint!
With the
file_mode
being passed as keyword only to thewrite
function, this breaks linters which are raising an error:Is the decorator really necessary to open the file and take care of the handling? Would it be possible to just add the 2 arguments to the function and do the file handling within it?