Skip to content

Modified flopy/modflow/ load methods to allow better subclassing.#986

Closed
CesarRodriguezPereira wants to merge 1 commit into
modflowpy:developfrom
CesarRodriguezPereira:Easier-subclassing
Closed

Modified flopy/modflow/ load methods to allow better subclassing.#986
CesarRodriguezPereira wants to merge 1 commit into
modflowpy:developfrom
CesarRodriguezPereira:Easier-subclassing

Conversation

@CesarRodriguezPereira
Copy link
Copy Markdown

@CesarRodriguezPereira CesarRodriguezPereira commented Aug 31, 2020

In realtion to issue #984
Modified almost every load method in the flopy/modflow/ classes, changing hard coded references to the class in a @staticmethod def load(f, ...) to @classmethod def load(cls, f, ...). This will allow for better subclassing and it's a more pythonic way to write alternative constructors, even if it's unlikely that many people will go that deep into subclassing the library.

The following files [mfchd, mfdrn, mfdrt, mfghb, mfriv, mfwel] didn't have their load methods altered because they used Package.load as an alternative constructor. Changing those to classmethod and replacing the class passed as a parameter to cls should acomplish the same as the applied changes.

mfpar.py load method was not modified as it doesn't return an instance of the object (which seems weird).

Modified almost every load method in the flopy/modflow/ classes, changing hard coded references to the class in a @staticmethod def load(.....) to @classmethod def load(cls, .....).

The following files [mfchd, mfdrn, mfdrt, mfghb, mfriv, mfwel] didn't have their load methods altered because they used Package.load as an alternative constructor. Replacing the class passed as a parameter to cls should acomplish the same as the applied changes.

mfpar.py load method was not modified as it doesn't return an instance of the object (which seems weird).
@CesarRodriguezPereira
Copy link
Copy Markdown
Author

Ok, I've just seen you already implemented the @classmethod 20 minutes ago, you do work fast!

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

Successfully merging this pull request may close these issues.

1 participant