-2

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.

David542
  • 104,438
  • 178
  • 489
  • 842
  • 2
    Python 2.7 goes out of support next January. You must upgrade now – Daniel Roseman Oct 10 '19 at 19:17
  • 1
    Keep in mind, type annotations in Python are merely suggestions - the interpreter isn't going to hold anyone to adhere to the types that have been annotated. That being said, the only support that Python 2 has for type annotations is through [specially formatted comments](https://stackoverflow.com/a/35230792/4739755) – b_c Oct 10 '19 at 19:18
  • Every version of Python is strongly typed. So, are you asking how to use type annotations in Python 2.7? – juanpa.arrivillaga Oct 10 '19 at 19:39
  • Does this answer your question? [Type hinting in Python 2](https://stackoverflow.com/questions/35230635/type-hinting-in-python-2) – AMC Feb 08 '20 at 02:19

1 Answers1

0

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.

Joanna
  • 271
  • 1
  • 9
  • 1
    As @b_c says in the comments you can still you a type checker with python 2.7, you just need to include the annotations in comments (see [here](https://mypy.readthedocs.io/en/latest/python2.html)) – tomjn Oct 10 '19 at 19:29