问题标签 [pytype]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
144 浏览

python - Python: pytype-compatible type() command?

Is there any type-like command that will recurse through collections to return a pytype-style declaration if such a thing exists? I realize that collections with heterogeneous elements may be problematic.

For example, I would like to see output similar to this:

0 投票
0 回答
85 浏览

python - pytype 为(显然)有效的类方法返回 bad-concrete-type

以下代码无法使用 PyType 进行类型检查:

出现以下错误get

我在https://gist.github.com/brunokim/e86367ed63cbd52d96b3564f502831b2添加了一个完整的 MWE 。我是否缺少正确注释类属性的内容things?我注意到 pyi 文件与实例属性没有什么不同。

0 投票
2 回答
1325 浏览

python - 在 Python 类中进行类型检查

我正在尝试使用静态类型检查工具来检查对变量的错误分配。例如,将字符串分配给 int 变量。

我试过pytypemypy。两者都没有给我任何警告。

我希望静态类型检查工具可以在上面的行中给我一个警告:

我是否需要使用一些选项或其他辅助工具来检测这种赋值语句?

0 投票
1 回答
555 浏览

python - 'pytype' 为使用 TypeVar 的函数引发 FAILED

我正在使用pytype(2019.10.17,到目前为止的最新版本)作为我的代码类型检查器来开发一个工具,它可以通过使用索引文件随机读取msgpack文件,该文件记录位置(msgpack文件中的偏移量) ) 每条消息(存储在 msgpack 中的值)。

在消息类型的多样性方面,我使用typing.TypeVar泛型类型来实现。pytype 使用 TypeVar 时遇到问题。

使用命令运行上述代码pytype main2.py

如前所述https://google.github.io/pytype/errors.html#invalid-annotation,这种情况是无效注释。

为什么代码不能通过pytype检查?

0 投票
2 回答
246 浏览

python-3.x - Type hinting a method that returns a string or error in Python 3.7+

I have a Python script that starts with a method searching for a CSV file in the current directory or downloads a directory to make some processing. If no CSV file is found, the program should not run and exit with an error message.

I type annotated a tentative method as follows:

If I type check with eg. pytype I get the error:

What would you recommend doing to make this code compliant?

0 投票
2 回答
29412 浏览

python - 如何使用 pip install 修复“退出状态为 1 的命令出错”

我在安装 pytype 时遇到了一些问题,pip install如下所示:

操作系统:CentOS 7

蟒蛇:Python 3.6

点数:20.0.2

0 投票
1 回答
83 浏览

python-3.x - 类型检查时中断导入周期

我已经将一个大类实现拆分为不同的包 [1],并在方法体内使用了导入以避免编译周期,如下所示:

但是,pytype 对此并不满意,在到达导入周期时找不到 pyi 文件:

文件“/home/bkim/Projects/mwe/model.py”,第 6 行,在 is_prime:无法为“方法”导入 pyi [pyi-error]

找不到“模型”的 pyi,引用自“方法”

我怎样才能避免这种情况并仍然进行类型检查?

[1] 实际上,我只用了一种很小的实用方法就完成了这项工作。无需大喊将一个类拆分到多个包中。

0 投票
1 回答
172 浏览

python - Pytype 找不到 python3 解释器

我正在尝试pytype在一个项目上运行,但我不断收到错误消息CRITICAL Could not find a valid python3.5 interpreter in path (found Python 2.7.17)。但是,我安装了 python3。我也有别名alias python="python3"

  • python -V- Python 3.6.9
  • python3 -V- Python 3.6.9
  • python2 -V- Python 2.7.17

我怎么跑pytype

0 投票
0 回答
300 浏览

python-3.x - pytype 使用 attrs 默认工厂装饰器引发错误

mypy没有错误,但pytype无法处理此代码并上升attribute-error。我该如何解决?

代码:

日志:

版本:

PS我想不# pytype: disable=attribute-error排队@x.default

0 投票
1 回答
154 浏览

python - 工厂方法的类型注解

假设我有一个用作工厂的类方法:

现在我想为此添加 pytype 注释。from_file我应该为类方法使用哪些注释?仅将其标记为-> 'Foo'不会捕获在派生类(如Bar. 所以print调用中的表达式不会知道它是 aBar和 has lines。我如何表达结果将是参数的一个实例cls