让 6 和 6.moves 模块在 pycharm 中自动完成 [英] Getting six and six.moves modules to autocomplete in pycharm

查看:26
本文介绍了让 6 和 6.moves 模块在 pycharm 中自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以导入六个模块以在 pycharm 中工作?我意识到该模块在使用导入时会混淆 pycharm,但希望有某种解决方法.

Is it possible to get imports for the six module to work in pycharm? I realize the module does some playing with imports that confuses pycharm but was hoping there was some type of workaround.

例如,我希望以下内容在 pycharm 或 intellij 中正常工作::

For example, I'd like the following to work properly in pycharm or intellij::

from six.moves import BaseHTTPServer

推荐答案

导入是动态的,因此pycharm无法对代码进行任何静态分析来确定类型信息.

The imports are dynamic so pycharm can't do any static analysis of the code to determine the type information.

Pycharm 通过使用静态类型定义文件(设置 -> 语言和框架 -> Javascript -> 库)为 javascript 等语言解决了这个问题.

Pycharm gets around this for languages like javascript by using static type definition files (Settings -> Languages & Frameworks -> Javascript -> Libraries).

这是 python 的等价物:https://www.jetbrains.com/help/pycharm/2016.2/using-python-skeletons.html - 一组并行的带有静态导出的 python 文件,允许进行静态分析.

This is the python equivalent: https://www.jetbrains.com/help/pycharm/2016.2/using-python-skeletons.html - a parallel set of python files with static exports allowing static analysis.

目前,骨架定义似乎真的是概念证明,因为它们非常稀疏(没有six,而django 模块存在,它几乎是空的——没有 django.utils.six.moves 可以直接复制).您可以手动添加所有 six.moves 导出,但这将是一项艰巨的工作.

At the present time the skeleton definitions seem to really be a proof of concept as they are very sparse (there is no six, and while a django module exists it is almost empty -- there is no django.utils.six.moves that you could just copy over). You could manually add all the six.moves exports but this would be a non-trivial effort.

如果您确实想尝试修改骨架文件,请在 OSX 上:

If you did want to try modifying the skeleton files, on OSX:

cd ~/Library/Preferences/PyCharm2016.2git 克隆 https://github.com/JetBrains/python-skeletons.git并修改其中的文件(尽管我实际上从未能够让它检测到我的更改)

cd ~/Library/Preferences/PyCharm2016.2 git clone https://github.com/JetBrains/python-skeletons.git and modify files in there (although I was never actually able to get it to detect my changes)

这篇关于让 6 和 6.moves 模块在 pycharm 中自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆