- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
使用 python 3,可以选择使用类型提示。
我的问题是,如果一个函数返回 None,应该添加它还是留空。
即
def hint(p:str) -> None:
pass
def no_hint(p:str):
pass
哪个 PEP 解决了这个问题?
最佳答案
要明确,并且始终为返回 None
-> None
因为否则,对于不带参数的函数,类型检查器会假定您根本没有使用类型提示。例如,def foo():
是要返回 None
,还是只是没有类型提示?
PEP 484 - Type Hints间接解决了这个问题:
Note that the return type of
__init__
ought to be annotated with-> None
. The reason for this is subtle. If__init__
assumed a return annotation of-> None
, would that mean that an argument-less, un-annotated__init__
method should still be type-checked? Rather than leaving this ambiguous or introducing an exception to the exception, we simply say that__init__
ought to have a return annotation; the default behavior is thus the same as for other methods.
关于python - typehints -> None 或留空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48223558/
我一直在修改VS 2010模板。到目前为止,我已经可以从模板创建vb.net类库项目。 但是,一件小事困扰着我。 在我的项目模板中,默认程序集名称与默认文件名相同。我将根 namespace 留为空白
我有一个 NSTextField,里面有一个 NSNumberFormatter。我见过一些文本字段,如果你将它们留空,它只会将之前的数字放回其中。我很好奇 Interface Builder 中是否
sql问题 我有这样的表格: id | Animal | country | gender | qty 1 | cow | USA | male | 6 2 | cow |
我正在尝试制作一个包含内容页面的网站。 我使用 go to chapter 1作为内容部分,当它点击时,它会处理 Chapter 1 这很好用,但有 1 个问题(总有一个问题)...我想让它看起来像维
我正在制作一个包含 4 个主视图的应用。我希望所有这些都保留在顶部的 LIST 菜单中(现在没问题)。 使用 Fragments,我可以在不执行其他 Activity 的情况下更改 View ,但是由
我正在定义一个 Form 类,它有一个文件字段并且不需要向它添加文件......但是每当我不提供文件时,表单都是无效的......所以有什么方法可以让我可以让用户选择是否添加文件吗??? 最佳答案 是
所以我尝试了之前帖子中关于这个问题的一些方法,但似乎没有一个对我有用(毫无疑问是用户错误)。 基本上,如果编辑文本留空,我的计算按钮就会崩溃。我需要发生的是,如果留空,则 edittext 的值为 0
我正在尝试提取 BufferedImage 的 10 px 方形部分并将它们添加到新的 BufferedImage 中,与 this drawImage tutorial 中显示的困惑示例非常相似。但
所以我正在使用 Postgres 和 Hibernate 4.2.2 以及这样的实体 @Entity(name = "Users") @Check(constraints = "email ~* '^
我正在尝试将列名为“邮政编码”、“2010 年人口”、“Land-Sq-Mi”和“每平方英里密度”的 CSV 文件导入我的测试表,该表名为 derp--这就是我在开头使用 drop 语句的原因,这样我
我正在尝试使用 usemin 插件来缩小并创建我的可分发文件。这是我的 Gruntfile.js: module.exports = function(grunt) { require('matc
在我的 HTML 中我有一个 ,并在 内我需要不同的文本行之间的垂直间距。我通过使用 实现了这一点具有对应于我想要的间距量的 CSS 类的元素。 例如,对于 5px 的间隙,我使用 与 heig
我有一个函数触发两个观察者 - keyboardWillShowNotification 和 KeyboardWillHideNotification,我基本上做的是在编辑时重置文本字段,模拟 的效果
这是一个非常奇怪的问题: Screenshoot 我确保图像大小相等,并且 Chrome 可以正确显示。为什么不是 IE 和 Firefox?对此有什么解决方案吗? 最佳答案 一个 li 的高度与另一
我是一名优秀的程序员,十分优秀!