nmlerr: Errors for NmlFile data

This module provides a collection of error types for reading Fortran namelist files. It also contains functions that utilize these exception classes efficiently.

exception cape.nmlfile.nmlerr.NmlError

Parent error class for nmlfile

Inherits from Exception

exception cape.nmlfile.nmlerr.NmlIndexError

Index errors for NmlFile

Inherits from IndexError

exception cape.nmlfile.nmlerr.NmlTypeError

Type errors for NmlFile

Inherits from TypeError

exception cape.nmlfile.nmlerr.NmlValueError

Value errors for NmlFile

Inherits from ValueError

cape.nmlfile.nmlerr.assert_isinstance(obj, cls_or_tuple, desc=None)

Conveniently check types

Applies isinstance(obj, cls_or_tuple) but also constructs and raises a useful NmlTypeError if test failes

Call:
>>> assert_isinstance(obj, cls, desc=None)
>>> assert_isinstance(obj, cls_tuple, desc=None)
Inputs:
obj: object

Object whose type is checked

cls: type

Single allowed class for obj

cls_tuple: tuple[type]

Typoe of allowed classes

Raises:

NmlTypeError

Versions:
  • 2023-06-06 @ddalle: v1.0

cape.nmlfile.nmlerr.assert_nextchar(c: str, chars: str, desc=None)

Assert that c is one of a specified list of characters

Call:
>>> assert_nextchar(c, chars, desc=None)
Inputs:
c: str

Character to be tested

chars: str

String of allowed characters

desc: {None} | str

Optional description