The KeywordArgs contract appears to have two deficiencies:
1) A missing arg with a Maybe[] contract is valid despite not being declared optional
[9] development (main)> kk = Contracts::KeywordArgs[a: Contracts::Maybe[String]]
[10] development (main)> kk.valid?({})
=> true
In practice, this is often not an issue because the function definition would be like
Contract Contracts::KeywordArgs[a: Contracts::Maybe[String]]
def foo(a: )
end
and Ruby would enforce the presence of a.
However this would break in the more esoteric case of
Contract Contracts::KeywordArgs[a: Contracts::Maybe[String]]
def foo(**kwargs)
end
2) Default values for optional args are not validated by Contracts
[6] development (main)> module Foo
[6] development (main)* Contract KeywordArgs[a: Optional[String]] => Any
[6] development (main)* def self.foo(a: 2)
[6] development (main)* end
[6] development (main)* end
[7] development (main)> Foo.foo
=> nil
The KeywordArgs contract appears to have two deficiencies:
1) A missing arg with a
Maybe[]
contract is valid despite not being declared optionalIn practice, this is often not an issue because the function definition would be like
and Ruby would enforce the presence of
a
.However this would break in the more esoteric case of
2) Default values for optional args are not validated by Contracts