# special Stack for integers
from stack import Stack


class IntStack(Stack):

    """
    Stack that accepts only integer elements.

    push - raise Exception if non-int pushed
    pop - raise Exception to pop on empty.
    >>>
    """

    def push(self: 'IntStack', n: int) -> None:
        """
        Push n if it's an integer, otherwise raise Exception

        >>> i = IntStack()
        >>> i.push(3)
        >>> i.pop()
        3
        """

        if isinstance(n, int):
            Stack.push(self, n)
        else:
            raise PushNonIntegerException

    def pop(self: 'IntStack') -> int:
        """
        Remove and return top element.  Raise exception if empty.

        >>> i = IntStack()
        >>> i.push(3)
        >>> i.pop()
        3
        """

        if self.is_empty():
            raise PopEmptyStackException
        else:
            Stack.pop(self)


class PushNonIntegerException(Exception):

    """Raised when non-integer push attempted"""

    pass


class PopEmptyStackException(Exception):

    """Raised when pop from empty stack attempted"""

    pass
