fast-aircraft-design / FAST-OAD

FAST-OAD: An open source framework for rapid Overall Aircraft Design
GNU General Public License v3.0
53 stars 26 forks source link

DataFile class should report an error when opening a non existent file #429

Closed christophe-david closed 2 years ago

christophe-david commented 2 years ago

Describe the bug When using DataFile to read a non existing file, no error is triggered and the obtained instance behave as if the file was empty.

To Reproduce

>>> import fastoad.api as oad
>>> my_vars = oad.DataFile("/non/existent/file")
>>> my_vars.names()
[]

Expected behavior The idea behind this behavior is to provide the ability to create a DataFile for a non-existing file, to populate it with variables and then to write it. But the drawback is that it does not warn when the user wants to read an existing file and just does a typo.

Maybe a class method DataFile.new(path) would allow to create a new instance with provide path, while the classic instantiation would require an existing file.