### Does WingIDE support PEP-484 (Type hints) for Python 2.7?

66
views
1
24 days ago by
PEP-484 (Type Hints) has been introduced with Python 3.5. PEP-484 is also proposing how to use type hints using Python 2.7. Does WingIDE support type hints for Python 2.7?
Community: Wing Python IDE

2
24 days ago by
Wing supports type hints under both Python 2 and Python 3.  We're working on better support for the typing module and the typeshed repository of .pyi files.
But how?

I have the following simple Python module that uses one of the formats, which is proposed in PEP-484 for Python 2.7:

class Proxy:

def __init__(self,
server=None,  # type: Optional[str]
user=None,  # type: Optional[str]
password=None  # type: Optional[str]
):
# type: (...) -> None

self.server   = server
self.user     = user

return
​

Then I use src\wingutils\generate_pi.py to generate the pi file. I get the following:

# coding: utf-8
# AUTO-GENERATED FILE -- DO NOT EDIT

class Proxy:

def __init__(self):
pass

__builtins__ = {}
__doc__ = None
__file__ = '.\\Proxy.py'
__name__ = 'Proxy'
__package__ = None

Which is not what I expect...

And of course it would be much nicer if Wing would use the original .py file itself for type hints.
written 24 days ago by Andreas Schumann
There's no need to generate a .pi file. Wing does require that the typing.Optional class be imported just like it would be in Python 3 code that didn't have the expression in comments. Did you import Optional via a from typing import Optional or the equivalent? You also need to add a copy of typing.py for Python 2 on your sys.path.
written 24 days ago by Wingware Support
I've installed now the typing module for Python 2.7.
How does Wing support me now in checking the type? E.g. if I code:
p = Proxy(server=4, user=2, password=True)​
which obviously is violating my type hints, how does Wing tell me about the type violation?

You mentioned that you plan to improve support for type annotations. What improvements do you have in mind?
written 18 days ago by Andreas Schumann
Wing 6 uses type hints to inform the source assistant, autocompleter, and other tools.  It does not warn about potential problems in your code (other than syntax errors and indent problems).  Wing 7 will warn about problems, including problems with types.
written 17 days ago by Wingware Support

With Optional (nor Union) I don't get any hints. Only if I set it to only one type (e.g. type: str). At least in the case of Optional it would be nice if Wing showed me the hints...

When will Wing 7 be released?

written 17 days ago by Andreas Schumann
It looks like Wing 6 has problems with some versions of typing.py.  We'll fix this in the next Wing 6 release.

Wing 7 should be released in the next few months.
written 17 days ago by Wingware Support