qgisred / QGISRed

GNU General Public License v2.0
23 stars 8 forks source link

ResourceWarning: unclosed file #97

Open wciezak opened 1 year ago

wciezak commented 1 year ago

Hello, when running "About..." I get the warning: "...\plugins\QGISRed\qgisred_plugins.py:2267: ResourceWarning: unclosed file dlg = QGISRedAboutDialog()". I suggest changing the code in the qgisred_about_dialog.py file from:

22        # version
23        metadata = os.path.join(os.path.dirname(os.path.dirname(__file__)), "metadata.txt")
24        if os.path.exists(metadata):
25            f = open(metadata, "r")
26            lines = f.readlines()
27            for line in lines:
28                if "version=" in line:
29                    self.versionLabel.setText("v." + line.replace("version=", ""))
30                    return

to:

22        # version
23        metadata = os.path.join(os.path.dirname(os.path.dirname(__file__)), "metadata.txt")
24        if os.path.exists(metadata):
25            with open(metadata, "r") as f:
26                lines = f.readlines()
27                for line in lines:
28                    if "version=" in line:
29                        self.versionLabel.setText("v." + line.replace("version=", ""))
30                        return
fmartine commented 1 year ago

Dear Wojciech, Thank you for your contribution. Indeed, incorporating the 'with' statement guarantees the closing of the metadata.txt file and avoids unexpected warnings. We will include this improvement in the next version 0.17