# person_sized.py
#
# ICS 33 Spring 2026
# Code Example
#
# A class that explicitly specifies that its objects are sized, by inheriting
# from collections.abc.Sized.

import collections.abc


_DAYS_PER_YEAR = 365


# When we inherit from collections.abc.Sized here, we get two things:
#
# (1) It's now clear that our intention is for Person objects to be sized,
#     i.e., that we be able to call Python's built-in len function and pass
#     it a Person.
# (2) If we hadn't specified a __len__ method, it would become impossible
#     to create a Person object without an exception being raised, meaning
#     that we couldn't ever have a Person that didn't meet its own stated
#     requirement.

class Person(collections.abc.Sized):
    def __init__(self, name, age):
        self._name = name
        self._age = age


    @property
    def name(self):
        return self._name


    @property
    def age(self):
        return self._age


    # We don't need to say anything special in our __len__ method.  This is
    # how we meet the stated requirement, but we don't have to match this up
    # in any way to our having inherited from collections.abc.Sized.
    def __len__(self):
        # It's fairly nonsensical for a Person to have a "length" that is
        # determined by its age in days, but we're focused on the mechanism
        # here.
        return self._age * _DAYS_PER_YEAR
