Polymorphic value annotation #1380
decorator-factory
started this conversation in
General
Replies: 1 comment 7 replies
|
Python's support for lambdas is pretty limited. Lambdas provide no way to bind to a symbol name, annotate parameter types, serve as a scope for type variables, define overloads, apply decorators, use async functionality, etc. A lambda is really just a syntactic shortcut for extremely simple functions that do not require any of these more advanced pieces of functionality. In cases where you need any of this added functionality, you should use a function rather than a lambda. |
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Is there any way to declare a polymorphic value type, not function type? For example, if I have a function like this:
I can then call f and store the return value:
g's type is inferred to be Callable[[A, A], A], and
x's value is inferred asLiteral[4, 6].However, I cannot create this annotation "from scratch":
I guess I could do it with a construction like this:
but is there a way without a function?
The use I have in mind for it is a container that stores a polymorphic function. Example:
Here I can't say that
firsthas typeLens[tuple[Any, Any], tuple[Any, Any], Any, Any], because there's a clear relation in it (given a tuple(A, C),firstcan extract the first elementAor replace the first element withB, yielding(B, C))All reactions