You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve Strict Equality To Account For Named Closures #852
Here, while add(1) is not add(1) both produce the same behavior, IDOM won't recognize that they're the same.
Proposed Actions
It turns out that we can fairly reliable look at a function's __qualname__, __closure__, and __defaults__ to determine whether it's the same function. The logic to check this would look like:
This will fail because both functions, while they may implement different logic, have the same qualname. This is basically the same reason that we cannot compare lambdas. Since they all have the same name.
There may be ways to work around this. For example, f1 and f1 were defined on different lines. You could check this using __code__.co_firstlineno.
I would think the same applies to named closures as well. This would make the implementation for all function types the same.
But to be bullet proof, would need to also check if the __file__ and lineno are also equivalent, since technically the same function definition can be copy pasted with potentially different decorators.
True. Though technically, all we really care about is whether, given the same inputs, the output is the same (assuming the function is pure). The file name then, only matters in so far as there might be different globals that the function is referencing.
Activity
Archmonger commentedon Dec 8, 2022
Alternatively, for function defs we can check if their code is equal using string equality
rmorshea commentedon Dec 8, 2022
I think we could probably skip the qualname check and allow lambda comparisons by, as you say, just checking byte code equivalence.
Archmonger commentedon Dec 8, 2022
I would think the same applies to named closures as well. This would make the implementation for all function types the same.
But to be bullet proof, would need to also check if the
__file__and lineno are also equivalent, since technically the same function definition can be copy pasted with potentially different decorators.rmorshea commentedon Dec 8, 2022
True. Though technically, all we really care about is whether, given the same inputs, the output is the same (assuming the function is pure). The file name then, only matters in so far as there might be different globals that the function is referencing.