Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect signature for BMI initialize method #30

Open
mcflugen opened this issue Jan 13, 2024 · 1 comment
Open

Incorrect signature for BMI initialize method #30

mcflugen opened this issue Jan 13, 2024 · 1 comment

Comments

@mcflugen
Copy link
Member

mcflugen commented Jan 13, 2024

According to the BMI spec, the filename argument for the BMI initialize method must not be optional and must be a string. Right now BmiHeat.initialize accepts either None, a file-like object, or a string. I think this should be changed so that it only accepts a string that is a path to a configuration file.

i.e.

def initialize(self, filename: str):
    with open(filename) as file_obj:
        self._model = Heat.from_file_like(file_obj)
    ...

Actually, in looking at what's there now, I think there's also a bug. Heat.from_file_like must take a stream, not a string

i.e.

Heat.from_file_like(file_obj.read())

should be

Heat.from_file_like(file_obj)
@mcflugen
Copy link
Member Author

I think it would be safe to use the empty string to indicate a default configuration.

def initialize(self, filename: str):
    if filename:
        with open(filename) as file_obj:
            self._model = Heat.from_file_like(file_obj)
    else:
        self._model = Heat()
    ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant