Skip to content
Commit 70fe588d authored by Douglas Raillard's avatar Douglas Raillard
Browse files

lisa.utils: Fix PartialInit param binding

FIX

Do not include the default value of parameters when checking when
binding the kwargs to signature. This is important in cases like that:

    class Base:
	def foo(a, b=1):
	    pass

	@kwargs_forwarded_to(foo)
	def bar(self, *args, **kwargs):
	    return self.foo(*args, **kwargs)

    class Derived(Base):
	def foo(a):
	    pass

In this scenario, calling Derived.bar() must not call Derived.foo() with
b=1, because Derived.foo does not accept this parameter.

This is particularly important as this pattern is typically used to
provide a base class with dynamic behavior based on e.g. callbacks, and
derived classes that specialize by setting the callback "in stone".

This pattern does break Liskov substitution principle, but is
nonetheless usually not an issue as long as foo() is somewhat private,
and is only used by the user in a monomorphic context.
parent db32d3e3
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment