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

Prevent left-hand-side assigning on flowline objects #942

Open
fmaussion opened this issue Feb 6, 2020 · 1 comment
Open

Prevent left-hand-side assigning on flowline objects #942

fmaussion opened this issue Feb 6, 2020 · 1 comment

Comments

@fmaussion
Copy link
Member

since flowline.section = new_section works, it is natural to want to try something like: flowline.section[88] = 0 and expect it to work.

The command above will silently do nothing.

Is there a way to prevent this in python by raising an error? The relevant code is here:

oggm/oggm/core/flowline.py

Lines 185 to 187 in a63521c

@section.setter
def section(self, val):
self.thick = (0.75 * val * np.sqrt(self.bed_shape))**(2./3.)

I really don't know if there is a simple way to check for this...

Thanks @drounce for the report

@fmaussion
Copy link
Member Author

Correction: the relevant code is here:

oggm/oggm/core/flowline.py

Lines 181 to 187 in a63521c

@property
def section(self):
return 2./3. * self.widths_m * self.thick
@section.setter
def section(self, val):
self.thick = (0.75 * val * np.sqrt(self.bed_shape))**(2./3.)

So the problem in this line:

flowline.section[88] = 0

Is that it's the getter which is called and then the returned array is indexed at 88 and then changed.

I think there is no way to prevent this to happen, and it seems to be a perfect example where "too much fancy" is sometimes not good...

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