这是我的代码:
class Person:
def __init__(self, id):
self.id = id
def __eq__(self, other: 'Person') -> bool:
return self.id == other.id
def compare(self, other: 'Person') -> bool:
return self.id == other.id
Run Code Online (Sandbox Code Playgroud)
mypy 扔error: Argument 1 of "__eq__" incompatible with supertype "object"。
但是如果我删除__eq__方法,mypy 不会抱怨它虽然compare与 相同__eq__,我该怎么办?
我想检查第二个.item元素包含一些文本
cy.get('.item').then(($items) => {
expect($items).to.have.length(2);
expect($items[1]).to.contain('Published');
});
Run Code Online (Sandbox Code Playgroud)
柏树抛出错误:TypeError: obj.is is not a function。
我也试过expect($items[1]).text.to.contain('Published');
这次错误是TypeError: Cannot read property 'contain' of undefined.
我现在正在阅读Learn Functional Programming with Elixir,在第 4 章中,作者谈到了尾调用优化,即尾递归函数将使用比体递归函数更少的内存。但是当我尝试了书中的例子时,结果却相反。
# tail-recursive
defmodule TRFactorial do
def of(n), do: factorial_of(n, 1)
defp factorial_of(0, acc), do: acc
defp factorial_of(n, acc) when n > 0, do: factorial_of(n - 1, n * acc)
end
TRFactorial.of(200_000)
# body-recursive
defmodule Factorial do
def of(0), do: 1
def of(n) when n > 0, do: n * of(n - 1)
end
Factorial.of(200_000)
Run Code Online (Sandbox Code Playgroud)
在我的电脑中,tail-recursive版本的beam.smp会使用2.5G~3G内存,而body-recursive只使用1G左右。我误解了什么吗?