Python
Java
PHP
IOS
Android
Nodejs
JavaScript
Html5
Windows
Ubuntu
Linux
Python 2 中的类型提示
In PEP 484 类型提示被添加到 Python 3 中 其中包括typing模块 在Python 2中有什么办法可以做到这一点吗 我能想到的就是有一个装饰器添加到方法中来检查类型 但这会在运行时失败 并且不会像提示所允许的那样更早被捕
python
python27
types
typehinting
pythontyping
类型提示 - 指定对象数组
如何将参数类型指定为数组 假设我有一个名为 Foo 的类 class Foo 然后我有一个接受该类类型作为参数的函数 function getFoo Foo f 当我传入一个 Foo 数组时 我收到一个错误 说 可捕获的致命错误 参数 1
php
Arrays
typehinting
从函数的关键字参数生成 TypedDict
foo py kwargs a 1 b c def consume a int b str gt None pass consume kwargs mypy foo py error Argument 1 to consume has in
python
typehinting
mypy
在 Python 3.5 中,如何指定函数作为类型提示?
指定变量应该是函数 相当于委托 Func
python
python3x
typehinting
statictyping
当内部函数返回可能为“None”的“Union”时,如何避免类型错误?
我在Python中遇到了一些关于联合 当然还有可选 的奇怪问题 也就是说 静态类型检查器似乎针对联合的所有成员而不是联合的成员测试属性 即看起来过于严格 例如 请考虑以下情况 import pandas as pd def test dum
python
pandas
typehinting
pythontyping
是否可以输入多种类型的提示?
我可以使用类型提示允许两种不同的类型吗 例如 范围 requester可以是以下任一者User or File function log User File requester 从 PHP 8 0 开始 这将是可能的包含联合类型 The 该
php
typehinting
php8
当 mypy 无法注释时,为什么它会抱怨列表理解?
为什么 Mypy 抱怨它需要列表理解变量的类型注释 而无法使用 MyPy 注释这样的变量 具体来说 如何解决以下错误 from enum import EnumMeta def spam y EnumMeta return x value
python
typehinting
mypy
pythontyping
如何在多个别名上定义递归 Python 类型?
我想要这个逻辑类型结构 from typing import List Dict Union ObjectType Dict str EntryType ListType List EntryType EntryType Union str
python
typehinting
mypy
pythontyping
Callable 基类无效?
有人可以解释为什么继承自非参数化和参数化Callable from typing import Callable from typing import NoReturn from typing import TypeVar T TypeVa
python
typehinting
mypy
如何输入最初为 None 但保证获得值的提示变量
我有一个类变量 如下所示 class MyClass def init self self value MyOtherClass None None self initialize value def initialize value se
python
typehinting
pythontyping
使用类型提示时如何向函数添加默认参数?
如果我有一个这样的函数 def foo name opts pass 我想给参数添加类型提示 我该怎么做 我假设的方式给了我一个语法错误 def foo name str opts dict gt str pass 以下不会引发语法错误 但
python
typehinting
pythontyping
mypy 列表中对象继承的问题
Python 3 6 5 和 mypy 0 600 我写了代码 from typing import List class Animal pass class Dog Animal def init self gt None super d
python
python3x
typehinting
mypy
如何获取对象属性的类型提示?
我想获取对象属性的类型提示 我只能获得该类的提示 而不能获得该类的实例 我尝试过使用foo instance class from here但这只显示了类变量 那么在示例中我如何获得类型提示bar class foo var int 42
python
python3x
typehinting
defrecord 构造函数中未强制执行类型提示
我使用创建了一个类型defrecord带有字段的类型提示 然而 我发现这些类型提示在构造函数中没有强制执行 我可以用它们做一些奇怪的事情 例如 请看下面的代码片段 user gt defrecord Person String name I
Clojure
typehinting
函数签名中的“TypeError:'type'对象不可下标”
为什么我在运行此代码时收到此错误 Traceback most recent call last File main py line 13 in
python
python3x
list
TypeError
typehinting
«
1
2
3
4
5
6