有没有办法让这项工作
from typing import Literal
def foo(bar: Literal["bar"]) -> Literal["foo"]:
foo = "foo"
return foo
bar = "bar"
foo(bar)
Run Code Online (Sandbox Code Playgroud)
以下是错误
foo.py:4: error: Incompatible return value type (got "str", expected "Literal['foo']")
foo.py:8: error: Argument 1 to "foo" has incompatible type "str"; expected "Literal['bar']"
Run Code Online (Sandbox Code Playgroud)
很明显,foo变量和bar是文字,因为它们被分配给文字,所以这是安全的,但 mypy 似乎没有跟踪这一点。有什么我想念的吗?
我正在使用流畅的断言,并且进行了以下测试:
result.Should().NotBeNull();
result.Link.Should().Equals("https://someinvoiceurl.com");
Run Code Online (Sandbox Code Playgroud)
效果很好,但是当我尝试这个时
result.Should().NotBeNull()
.Which.Link.Equals("https://someinvoiceurl.com");
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
“AndConstraint”不包含“Which”的定义,并且找不到接受“AndConstraint”类型的第一个参数的可访问扩展方法“Which”(您是否缺少 using 指令或程序集引用?)
我做错了什么?
我正在使用https://github.com/w0rp/ale插件。但它使VIM不太敏感......我有一个绑定ALETooggle上<leader>l。
默认情况下禁用它并在需要时通过键盘快捷键启用是很好的,我尝试穿上ALEDisable我的.vimrc但它给了我下面的错误
Error detected while processing /Users/daniel/.vimrc:
line 94:
E492: Not an editor command: ALEDisable
Press ENTER or type command to continue
Run Code Online (Sandbox Code Playgroud)
这是一个.vimrc可能引发问题的示例
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
Plugin 'w0rp/ale'
call vundle#end() " required
filetype plugin indent on " …Run Code Online (Sandbox Code Playgroud) 我正在尝试这样做
struct RwindIter {
iter: Box<dyn Iterator<Item = String>>,
}
fn build(i: impl Iterator<Item = String>) -> RwindIter {
RwindIter { iter: Box::new(i) }
}
Run Code Online (Sandbox Code Playgroud)
但我收到了这个错误
Compiling myml v0.1.0 (/Users/gecko/code/myml)
error[E0310]: the parameter type `impl Iterator<Item = String>` may not live long enough
--> src/main.rs:47:23
|
47 | RwindIter { iter: Box::new(i) }
| ^^^^^^^^^^^
|
note: ...so that the type `impl Iterator<Item = String>` will meet its required lifetime bounds
--> src/main.rs:47:23
|
47 | RwindIter { iter: Box::new(i) …Run Code Online (Sandbox Code Playgroud) 我正在关注本教程https://drup.github.io/2016/08/02/difflists/
并尝试在异构列表上实现交换,但它不进行类型检查
type ('ty, 'v) t =
| Nil : ('v, 'v) t
| Cons : 'a * ('ty, 'v) t -> ('a -> 'ty, 'v) t
let plus1 l = Cons ((), l) (* : ('a, 'b) t -> (unit -> 'a, 'b) t *)
let one x = Cons (x, Nil) (* : 'a -> ('a -> 'b, 'b) t *)
let l1 = Cons (1, Cons ("bla", Nil)) (* : (int -> string -> 'a, 'a) …Run Code Online (Sandbox Code Playgroud) I have some Flask-SQLAlchemy models and Flask-WTF forms generated with wtforms_alchemy to represent them. I implemented a method on each model to update its attributes from a form's data. For each new model and field I have to update these methods, which is annoying. Is there a way to make this more automatic, or a a feature in the libraries I'm using that I'm missing?
def edit_car(car_id):
form = CarForm(request.form)
if form.is_valid():
car = Car.query.get_or_404(car_id)
car.from_form(form) # Update car fields …Run Code Online (Sandbox Code Playgroud) 我在这里面对这个配置https://github.com/developit/zero-to-preact/blob/master/webpack.config.js
plugins: [
['transform-react-jsx', { pragma: 'h' }]
]
Run Code Online (Sandbox Code Playgroud)
文档说
编译
string,默认为React.createElement.
替换编译JSX表达式时使用的函数.
请注意,从React v0.12开始,不推荐使用@jsx React.DOM编译指示
但没有关于'h'意味着什么的线索!它是什么?
我正在阅读https://www.abubalay.com/blog/2018/04/08/recursive-ascent,它做了我无法理解的事情
let Elements(array) = elements;
Run Code Online (Sandbox Code Playgroud)
这种表达是什么意思?它在创建array变量吗?那Elements(...)!!
问候
我遵循了砖蛇游戏的整个教程,但我遇到了这个错误
[typecheck -Wdeferred-out-of-scope-variables] [E] • Variable not in scope:
paused :: Lens.Micro.Type.Getting Bool Game Bool
• Perhaps you meant ‘_paused’ (line 24)
Run Code Online (Sandbox Code Playgroud)
完整代码在这里https://github.com/dhilst/brick-stake-tutorial-exercice-
重要的部分是这个
{-# LANGUAGE TemplateHaskell, FlexibleContexts #-}
module Snake where
import Control.Applicative ((<|>))
import Control.Monad (guard)
import Data.Maybe (fromMaybe)
import Data.Sequence (Seq, ViewL(..), ViewR(..), (<|))
import qualified Data.Sequence as S
import Lens.Micro ((%~), (&), (.~), (^.))
import Lens.Micro.TH (makeLenses)
import Linear.V2 (V2(..), _x, _y)
import System.Random (Random(..), newStdGen)
-- Types
data Game =
Game
{ _snake :: …Run Code Online (Sandbox Code Playgroud)