First time here? Check out the FAQ!
1

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

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 Wing IDE support type hints for Python 2.7?

Andreas Schumann's avatar
21
Andreas Schumann
asked 2018-04-27 10:54:00 -0600
Wingware Admin's avatar
231
Wingware Admin
updated 2019-03-13 08:31:21 -0600
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

1

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.

Wingware Support's avatar
4.2k
Wingware Support
answered 2018-04-27 11:51:00 -0600
edit flag offensive 0 remove flag delete link

Comments

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
        self.password = password

        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.

Andreas Schumann's avatar Andreas Schumann (2018-04-27 12:15:00 -0600) edit

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.

Wingware Support's avatar Wingware Support (2018-04-27 13:04:00 -0600) edit

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?

Andreas Schumann's avatar Andreas Schumann (2018-05-04 05:23:00 -0600) edit

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.

Wingware Support's avatar Wingware Support (2018-05-04 10:29:00 -0600) edit

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?

Andreas Schumann's avatar Andreas Schumann (2018-05-04 10:59:00 -0600) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer