pythonsyntax-highlightingsublimetextpython-typing

How to make SublimeText support Python 3's annotations?


I tested both SublimeText 2 and 3 and both are buggy:

If you test this code, you'll notice all code right after the : will not be syntax highlighted properly.

def foo(a, b) -> str:
    # Nothing gets properly colored from here
    # A bunch of code…
    return "bar"

I found some links explaining how to add your own syntax highlighting rules but I didn't find how to modify those already implemented in a attempt to fix them.

EDIT: Now knowing where to modify default syntax highlighting rules thanks to MattDMo, I tried to change line 385 of my file

        <key>end</key>
        <string>(\))\s*(?:(\:)|(.*$\n?))</string>

to

        <key>end</key>
        <string>(\))\s*(?:\->\s*[A-Za-z_][A-Za-z0-9_]*\s*)?(?:(\:)|(.*$\n?))</string>

But it didn't work.


Solution

  • I created my own version ~2 months ago, it still has some (serious) bugs, so don't hesitate to report those bugs on this github page or contribute a fix for it:

    https://github.com/petervaro/python

    Although there is a Cython version which is generated from the same file as the Python itself -> but it's absolutely a work-in-progress tmLanguage, so don't use it!:)


    UPDATE: It is now "stable" and ready for the serious work, so use it, share it, and please report bugs! :)