There's a recurring need for more control over how we compare and/or merge signatures.
These often involve some logic on parameter objects (with their name, kind, and optionally default and annotation), order, etc.
We'd like to have a clean framework that enables the user to easily and correctly define these functions, reusing much of the common logic.
Examples:
- comparison Boolean operators/functions such as:
- operators/functions such as signature merging (
sig1 + sig2)
- function that gives a score or more complex information about how appropriate it is to feed the function with signature
sig1 to an input value of function with signature sig2
Don't miss this comment that proposes a design.
Notes
Return type of a comparison
Must cases might just need a Boolean, like with x == y or x <= y (or issubset, issubclass, etc.).
But in some cases, such as with self-organizing code (or less crazily: validation scores), we'd like to have a numerical (or more generally, vectorial) score, or more generally, some "comparable" type that can be used to do things like "best match".
Use a key function or a binary comparison function as the specifier?
Might want to express comparisons based on key functions like builtin sorted, max etc. do. What are the pros/cons? It seems like a cleaner design enabling easier UX (and obviously, a big pro is the interface-consistency with familiar builtins). But, for example, is it complete? Are there things we cannot do with key functions that we can with the usual binary operator way (specifying comparison function via a two-element boolean function such as compare(x, y)).
For example, how would comparison scores be derived from key functions? Even if it's possible to "fit" any comparison function with vectorial key functions, would it be the most intuitive way of expressing it?
References
Related issues
Further notes
The definition of signature equality
Sig doesn't redefine it -- the builtin is used, which boils down to using the following (acts basically as a "key function"):
def _hash_basis(self):
params = tuple(param for param in self.parameters.values()
if param.kind != _KEYWORD_ONLY)
kwo_params = {param.name: param for param in self.parameters.values()
if param.kind == _KEYWORD_ONLY}
return params, kwo_params, self.return_annotation
There's a recurring need for more control over how we compare and/or merge signatures.
These often involve some logic on parameter objects (with their name, kind, and optionally default and annotation), order, etc.
We'd like to have a clean framework that enables the user to easily and correctly define these functions, reusing much of the common logic.
Examples:
sig1 == sig2: equality (more precisely "equivalence relation") of two signaturessig1 <= sig2: comparison (more precisely "total order relation" asissubset,issubclassetc.)sig1 + sig2)sig1to an input value of function with signaturesig2Don't miss this comment that proposes a design.
Notes
Return type of a comparison
Must cases might just need a Boolean, like with
x == yorx <= y(orissubset,issubclass, etc.).But in some cases, such as with self-organizing code (or less crazily: validation scores), we'd like to have a numerical (or more generally, vectorial) score, or more generally, some "comparable" type that can be used to do things like "best match".
Use a key function or a binary comparison function as the specifier?
Might want to express comparisons based on key functions like builtin
sorted,maxetc. do. What are the pros/cons? It seems like a cleaner design enabling easier UX (and obviously, a big pro is the interface-consistency with familiar builtins). But, for example, is it complete? Are there things we cannot do with key functions that we can with the usual binary operator way (specifying comparison function via a two-element boolean function such ascompare(x, y)).For example, how would comparison scores be derived from key functions? Even if it's possible to "fit" any comparison function with vectorial key functions, would it be the most intuitive way of expressing it?
References
signatures.pycodeRelated issues
code_to_dag. But that's only forcode_to_dag. Still, the long issue has some reflections about signature comparison.Further notes
The definition of signature equality
Sigdoesn't redefine it -- the builtin is used, which boils down to using the following (acts basically as a "key function"):