
# #################################################
# Managed attributes
# 
#    How to make "shares" into a MANAGED attribute


class Stock:
    def __init__(self, name, shares, price):
        self.name = name
        self.set_shares(shares)			# Accessor methods
        self.price = price

    # Function that layers the "set" operation
    def set_shares(self, value):
        if not isinstance(value, int):
            raise TypeError("Value is not an integer")
        self._shares = value

    # Function that layers the "get" operation
    def get_shares(self):
        return(self._shares)


s = Stock('IBM', 50, 91.1)	## Access __init__( )

# Trouble:
#
# We can update shares with an INTEGER:
#
s.set_shares(100)			# Correct
print(s.__dict__)

# We MUST use  set_shares( ) to update  _shares:
#
s.set_shares([1, 0, 0])			# INCorrect
s.shares = [1, 0, 0]			# Raises exception !!!
print(s.__dict__)

# How to make   s.shares = ...  work AGAIN ???





