|
|
|
|
|
by pansa2
2086 days ago
|
|
> There is a numbers.Number for that That won't help if I want to square a matrix, or a polynomial. > typing_extensions.Protocol helps support the general duck typing "any object that has method x" Even if there's a `powerable` protocol that could be used to annotate `square` and `cube`, how would you annotate a slightly more complex function like `poly`? def square(x): return x**2
def cube(x): return x**3
def poly(x): return 3 * x**2 + 2 * x
|
|
What’s you want is something like “commutative multiplication”