Type hinting in Python 2 -


in pep 484, type hinting added python 3 inclusion of typing module. there way in python 2? can think of having decorator add methods check types, fail @ runtime , not caught earlier hinting allow.

according suggested syntax python 2.7 , straddling code in pep 484 defined type hinting, there alternative syntax compatibility python 2.7. not mandatory don't know how supported is, quoting pep:

some tools may want support type annotations in code must compatible python 2.7. purpose pep has suggested (but not mandatory) extension function annotations placed in # type: comment. such comment must placed following function header (before docstring). example: following python 3 code:

def embezzle(self, account: str, funds: int = 1000000, *fake_receipts: str) -> none:     """embezzle funds account using fake receipts."""     <code goes here> 

is equivalent following:

def embezzle(self, account, funds=1000000, *fake_receipts):     # type: (str, int, *str) -> none     """embezzle funds account using fake receipts."""     <code goes here> 

for mypy support, see type checking python 2 code.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -