pythonpython-2.7typesstrong-typing

Typing for python2.7?


Is there a way to do the following in python2.7:

class DailyPriceObj:
    def __init__(self):
        self.date = None    #datetime.date
        self.sd_buy = None  # float
        self.hd_buy = None  # float
        self.sd_rent = None # float
        self.hd_rent = None # float
        self.revenue = None # float

I've used typing in later versions, but for a certain project the codebase is 2.7.


Solution

  • As you can read in the documentation:

    https://github.com/python/typing

    This GitHub repo is used for development of the typing module defined by PEP 484. The module is available in Python since version 3.5.0 on a provisional basis until Python 3.7.0.

    So, no - you cannot use it with 2.7, sadly.