Module csw.SemesterId

Classes

class Semester (*args, **kwds)
Expand source code
class Semester(Enum):
    A = 1
    B = 2

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

Color.RED

  • value lookup:

Color(1)

  • name lookup:

Color['RED']

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

Ancestors

  • enum.Enum

Class variables

var A

The type of the None singleton.

var B

The type of the None singleton.

class SemesterId (year: int,
semester: Semester)
Expand source code
@dataclass
class SemesterId:
    """
    Represents a unique semester id

    Args:
        year (int): year for semester
        semester (Semester): observing semester
    """
    year: int
    semester: Semester

    def __str__(self):
        return f"{self.year}{self.semester.name}"

    @staticmethod
    def _parseSemester(semesterStr: str) -> Semester:
        if not semesterStr in Semester.__members__:
            semesters = ", ".join(Semester.__members__.keys())
            raise ValueError(
                f"Failed to parse semester {semesterStr}: {semesterStr} is not a member of Enum ({semesters})")
        return Semester[semesterStr]

    @classmethod
    def make(cls, semesterId: str) -> Self:
        n = len(semesterId) - 1
        yearStr, semesterStr = semesterId[:n], semesterId[n:]
        if not (yearStr.isnumeric()):
            raise ValueError(f"{yearStr} should be valid year")
        year = int(yearStr)
        semester = cls._parseSemester(semesterStr)
        return SemesterId(year, semester)

Represents a unique semester id

Args

year : int
year for semester
semester : Semester
observing semester

Static methods

def make(semesterId: str) ‑> Self

Instance variables

var semesterSemester

The type of the None singleton.

var year : int

The type of the None singleton.