- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
它在 PyCharm 2016 中有效,但在 PyCharm 2017 中无效:
“解决方案”:PyCharm 2017.2.x 支持 NamedTuple
来自 typing
并且我不需要再使用 .pyi
文件。
最佳答案
编辑#1:
我发现了这个问题:https://youtrack.jetbrains.com/issue/PY-18597并且有一个答案:
PyCharm 2017.1 EAP builds now always prefer stub files over Python files found on the Python path.
这意味着 Pycharm 将查找 .pyi
文件中存在的内容(如果存在这样的文件)并且它将使用仅此作为引用。所以你别无选择,只能在 .pyi 文件中声明所有函数。
您可以在 here 中找到一些关于如何避免潜在烦人的警告和错误的知识。
编辑#2:
是的,我可以确认 from ... import *
在 PyCharm 中没有按预期工作,这可能是一个错误,您可以为此打开一个问题(或者如果有人成功地完成了这项工作,请告诉我们怎么做)!
我根据这句话找到了解决方法:
Modules and variables imported into the stub are not considered exported from the stub unless the import uses the import ... as ... form or the equivalent from ... import ... as ... form.
如果您:from file_a import a as a, b as b ...
那么所有内容都会按预期取消标记,但是 from file_a ...
会给您以下警告:
Import resolves to its containing file... (Ctrl+F1)
This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items.
如解释的那样,不要 panic here这是一个关于模块名称可能被您的文件名遮蔽的警告(这不适用于您的情况!)
关于python - 我如何在 .pyi 文件中声明原始模块中的部分字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43151273/
它在 PyCharm 2016 中有效,但在 PyCharm 2017 中无效: “解决方案”:PyCharm 2017.2.x 支持 NamedTuple 来自 typing 并且我不需要再使用 .
如何自动创建 pyi 的样板代码文件? 我想创建一个 pyi pep484 中描述的类型提示文件其中包含所有方法名称。 我不想要魔法。我想在自动创建文件后添加类型信息。 我想避免复制+粘贴工作。 目标
你可以使用mypy的stubgen.py或其他工具 generate .pyi files automatically ,但 stubgen 包含检查 stub 文件准确性的附加建议。 如果我自动生成
在Python中,.pyi扩展名中的“i”代表什么? 在 PEP-484 ,它提到 .pyi 是“ stub 文件”,但没有关于扩展的助记符帮助。那么“i”是否意味着“包括”? “执行”? “接口(i
我使用 C++ 和 pybind11 构建了一个已编译的 Python 扩展(.pyd 文件)。我想为我的 .pyd 文件生成一个 Python 接口(interface) .pyi 文件。 有几个类
我正在尝试了解 python 3 的较低级别实现。 subprocess module 使用一个名为 _posixsubprocess 的模块。 。我尝试在系统中查找该模块的位置,发现它是一个 stu
在 Python 3 中,类型提示允许使用第三方工具,例如 mypy检查类型;然而,我发现类型检查语法与程序注释一起有点难看。使用 mypy,可以将 stub 函数和方法放入与 .py 文件位于同一目
我正在将 pylance 用于 vs 代码,它工作得非常好,除了因为我使用它,当我尝试从已安装的库中检查代码时,我只能访问 stub ,我认为是由 pylance 生成的。 例如,显示的有关函数的信息
在 VS Code 中,我尝试导入一个名为 foo.py 的模块,该模块具有类型提示 stub file foo.pyi。我想根据 .pyi 文件中的类型提示获得代码自动完成,如 PyCharm do
我想获取函数或类方法的注释。如果类型提示写在源代码中,那么我可以通过获取属性__annotations__来获取类型。 def hoge(n: int): ... print(hoge.__annot
当我在 PyCharm 中按住 ctrl 并单击导入名称时,它通常会将我带到 stub 文件而不是源文件。 例如,在 ssl 名称之后: import ssl 会带我去这样的地方: ~/pycharm
我是 Python 注释的新手(类型提示)。我注意到 pyi 中的许多类定义文件继承到 Generic[_T] , 和 _T = TypeVar('_T') . 我很困惑,_T 是什么意思?这里的意思
我是一名优秀的程序员,十分优秀!