Skip to content

Commit

Permalink
Raise error on slicing a dt
Browse files Browse the repository at this point in the history
Closes #57
  • Loading branch information
rjfarmer committed Feb 29, 2024
1 parent ddc5227 commit da40381
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gfort2py/fDT.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,18 @@ def __contains__(self, key):
return key in self.keys()

def __getitem__(self, key):
if isinstance(key, slice):
raise AttributeError("Scalar derived type can't be sliced")

if key in self._dt_args:
return self._dt_args[key].from_ctype(getattr(self.cvalue, key))
else:
raise KeyError(f"{key} not present in {self._dt_obj.name}")

def __setitem__(self, key, value):
if isinstance(key, slice):
raise AttributeError("Scalar derived type can't be sliced")

if key in self._dt_args:
self.from_param({key: value})
else:
Expand Down

0 comments on commit da40381

Please sign in to comment.