Ask Your Question
1

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

asked 2018-04-27 10:54:00 -0500

updated 2019-03-13 08:31:21 -0500

Wingware Admin gravatar image

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?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2018-04-27 11:51:00 -0500

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.

edit flag offensive delete link more

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 gravatar imageAndreas Schumann ( 2018-04-27 12:15:00 -0500 )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 gravatar imageWingware Support ( 2018-04-27 13:04:00 -0500 )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 gravatar imageAndreas Schumann ( 2018-05-04 05:23:00 -0500 )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 gravatar imageWingware Support ( 2018-05-04 10:29:00 -0500 )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 gravatar imageAndreas Schumann ( 2018-05-04 10:59:00 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-04-27 10:54:00 -0500

Seen: 17 times

Last updated: Mar 07