我试图谷歌寻求答案,但也许没有广泛可用的研究,或者我可能没有使用正确的条款.
基本上,我想知道打字时按键之间的平均时间.我想知道这个的原因是我正在进行模糊搜索,这将在下拉列表中使用.我们可以采取一些措施来提高结果的准确性,但这会导致速度变慢.但是,如果这样的速度仍然低于按键间时间的合理阈值,则实施该改变是有意义的.
任何帮助,将不胜感激.
为什么像Scala这样具有非常强大的静态类型系统的语言允许以下结构:
scala> List(1, List(1,2))
res0: List[Any] = List(1, List(1, 2))
Run Code Online (Sandbox Code Playgroud)
如果你替换List,同样的事情Array.我在OCaml中学习了函数式编程,它会在编译时拒绝相同的代码:
# [1; [1;2]; 3];;
Characters 4-9:
[1; [1;2]; 3];;
^^^^^
Error: This expression has type 'a list
but an expression was expected of type int
Run Code Online (Sandbox Code Playgroud)
那么为什么Scala允许这个编译呢?
我使用的是typescript 1.7.5,类型为0.6.9,角度为2.0.0-beta.0.
如何解决Duplicate identifier由于打字定义文件而导致的打字稿编译错误消息?
该Duplicate identifier错误发生在以下目录的定义文件中:
node_modules/angular2/typings/es6-shim/es6-shim.d.ts
node_modules/angular2/typings/jasmine/jasmine.d.ts
node_modules/angular2/typings/zone/zone.d.ts
typings/browser/ambient/es6-promise/es6-promise.d.ts
typings/browser/ambient/es6-shim/es6-shim.d.ts
typings/browser/ambient/jasmine/jasmine.d.ts
typings/browser/ambient/karma/karma.d.ts
typings/browser/ambient/zone.js/zone.js.d.ts
Run Code Online (Sandbox Code Playgroud)
编译器在node_modules/angular2目录中做了什么,因为我将其排除在外tsconfig.json?
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
如果我改变了exclude部分tsconfig.json:
"exclude": [
"node_modules",
"typings"
]
Run Code Online (Sandbox Code Playgroud)
但是在添加以下内容之后我又得到了相同的Duplicate identifier编译错误:
/// <reference path="../../typings/browser.d.ts" />
Run Code Online (Sandbox Code Playgroud)
typings.json
{
"name": "example-mean-app-client",
"dependencies": {},
"devDependencies": {},
"ambientDependencies": { …Run Code Online (Sandbox Code Playgroud) 我有一个函数,它len在其中一个参数上使用函数并迭代参数.现在我可以选择是否使用Iterable或使用注释类型Sized,但两者都会出错mypy.
from typing import Sized, Iterable
def foo(some_thing: Iterable):
print(len(some_thing))
for part in some_thing:
print(part)
Run Code Online (Sandbox Code Playgroud)
给
error: Argument 1 to "len" has incompatible type "Iterable[Any]"; expected "Sized"
Run Code Online (Sandbox Code Playgroud)
而
def foo(some_thing: Sized):
...
Run Code Online (Sandbox Code Playgroud)
给
error: Iterable expected
error: "Sized" has no attribute "__iter__"
Run Code Online (Sandbox Code Playgroud)
由于本期没有Intersection讨论,我需要有一些混合类.
from abc import ABCMeta
from typing import Sized, Iterable
class SizedIterable(Sized, Iterable[str], metaclass=ABCMeta):
pass
def foo(some_thing: SizedIterable):
print(len(some_thing))
for part in some_thing:
print(part)
foo(['a', 'b', …Run Code Online (Sandbox Code Playgroud) 我最近尝试my Array @a = 'a'..'z';和my Array @a = @('a'..'z');。
两者都会产生以下错误:
Type check failed in assignment to @a; expected Array but got Str ("a")
in block <unit> at <unknown file> line 1
Run Code Online (Sandbox Code Playgroud)
但是,在没有类型的情况下进行初始化会起作用,并且似乎最终会产生一个Array:
> my @a = 'a'..'z';
> @a.^name
Array
Run Code Online (Sandbox Code Playgroud)
为什么会这样呢?
我用以下代码编写了一个程序:
import pandas as pd
import numpy as np
from typing import Tuple
def split_data(self, df: pd.DataFrame, split_quantile: float) -> Tuple(pd.DataFrame, pd.DataFrame):
'''Split data sets into two parts - train and test data sets.'''
df = df.sort_values(by='datein').reset_index(drop=True)
quantile = int(np.quantile(df.index, split_quantile))
return (
df[df.index <= quantile].reset_index(drop=True),
df[df.index > quantile].reset_index(drop=True)
)
Run Code Online (Sandbox Code Playgroud)
程序返回以下错误:TypeError: Type Tuple cannot be instantiated; use tuple() instead. 我明白了,我可以通过更换解决我的代码Tuple(pd.DataFrame, pd.DataFrame)有tuple(),但我失去的信息的一部分,我的元组将包括两只大熊猫的数据帧。
请您帮帮我,如何解决错误并同时不丢失信息?
我的DIV标签里面有文字.是否可以使用打字效果更改循环中的文本内容,在其中键入,然后向后删除字母并重新开始使用新文本?这有可能与jquery?
假设我想创建一个函数,它将lambda函数(Callable)作为参数,其中lambda函数将向量作为输入(定义为numpy数组或numpy矩阵)并返回一个新向量.如何使用numpy类型声明Callable的类型签名?
我最初的尝试看起来像这样:
def some_func(calc_new_vector: Callable[[np.array], np.array], ...other-params...) -> SomeType:
...do stuff...
...return...
Run Code Online (Sandbox Code Playgroud)
但是,这会在运行解释器时导致错误:
TypeError: Callable[[arg, ...], result]: each arg must be a type. Got <built-in function array>.
Run Code Online (Sandbox Code Playgroud) 我有几个分享一些字段的命名元组.我有一个接受这些元组的函数,并保证只与共享字段交互.我想在mypy中检查这样的代码.
代码的一个例子是:
from typing import NamedTuple
class Base(NamedTuple):
x: int
y: int
class BaseExtended(NamedTuple):
x: int
y: int
z: str
def DoSomething(tuple: Base):
return tuple.x + tuple.y
base = Base(3, 4)
base_extended = BaseExtended(5, 6, 'foo')
DoSomething(base)
DoSomething(base_extended)
Run Code Online (Sandbox Code Playgroud)
当我在这段代码上运行mypy时,我得到一个可预测的错误:
mypy_example.py:20:错误:"DoSomething"的参数1具有不兼容的类型"BaseExtended"; 预期"基地"
有没有办法构建我的代码并保持mypy typechecking?我不能从Base继承BaseExtended,因为NamedTuple继承实现中存在一个错误:
https://github.com/python/typing/issues/427
我也不想使用一个丑陋的"Union [Base,BaseExtended]",因为当我尝试对一个List进行类型检查时会出现这种情况,因为"List [Union [Base,BaseExtended]]"不等于"List [BaseExtended] ]"由于关于变体/协变类型的一些mypy魔术:
https://github.com/python/mypy/issues/3351
我应该放弃这个想法吗?
我在整个项目中使用 Python 类型模块,我想知道是否有一种方法可以指定给定对象必须同时具有两种不同的类型。当您指定了两个协议,并期望单个对象满足这两个协议时,这种情况最明显地出现:
class ReturnsNumbers(Protocol):
def get_number(self) -> Int:
pass
class ReturnsLetters(Protocol):
def get_letter(self) -> str:
pass
def get_number_and_letter(x: <what should this be?>) -> None:
print(x.get_number(), x.get_letter())
Run Code Online (Sandbox Code Playgroud)
提前致谢!
typing ×10
python ×5
python-3.x ×2
animation ×1
arrays ×1
jquery ×1
keypress ×1
mypy ×1
namedtuple ×1
numpy ×1
ocaml ×1
performance ×1
perl6 ×1
python-3.5 ×1
raku ×1
range ×1
scala ×1
text ×1
typescript ×1