推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
yech1990
V2EX  ›  Python

vim 读写 Python 文件,怎么添加 typing lints 的支持?

  •  
  •   yech1990 · Mar 7, 2018 · 2153 views
    This topic created in 2991 days ago, the information mentioned may be changed or developed.

    Python PEP 484PEP 526 加入了类型注释,然而现在网上 vim 的插件都没到位。

    语法检查插件各种小 bug 不说,就是基本的 highlight 支持也没搜索到解决方案。

    请问大家是怎么解决这个问题的?

    换 IDE 什么的就不说了,编辑服务端文件为主,vim 是刚需。


    另外 Guido 似乎花了不少精力在推 typing 这个事情,后面的 PEP 563 改进更加彻底。所以还是像遵循 PEP 8 去适应新的规则吧,免得几年后又得像 2to3 那样改代码。

    Supplement 1  ·  Mar 8, 2018

    自己定义了syntax,算是稍微解决了。

    两个痛点

    • 网上已有的vim插件不支持类型注释,导致有的类型高亮了,有的没有,风格十分凌乱,而且严重影响了阅读体验。
    • 其他IDE(pycharm也不例外)在处理这个问题上也十分诡异。类型注释在动态语言上的作用是隐形的,类型不是代码的重点,类型是喂给机器的;函数和方法才是给人看的。而现在这些IDE都直接套用了Java之类的hinting,死板地高亮类型。所以我自己把注释变成灰色+斜体,阅读体验好了很多。

    效果对比:

    20180308035737.png 20180308035215.png

    3 replies    2018-03-07 14:40:23 +08:00
    yech1990
        1
    yech1990  
    OP
       Mar 7, 2018 via Android
    Kenneth 大神新的项目也全部上类型注释了。

    https://github.com/kennethreitz/requests-html
    scriptB0y
        2
    scriptB0y  
       Mar 7, 2018
    搜索 highlight,你说的是实时高亮搜索结果吗?这个 Vim 原生支持的啊,:set hlsearch
    yech1990
        3
    yech1990  
    OP
       Mar 7, 2018 via Android
    @scriptB0y
    是说 typing annotation 的 highlight

    没搜索到解决方案。。。
    汗。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1394 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 17:07 · PVG 01:07 · LAX 10:07 · JFK 13:07
    ♥ Do have faith in what you're doing.