IronLanguages / ironpython3

Implementation of Python 3.x for .NET Framework that is built on top of the Dynamic Language Runtime.
Apache License 2.0
2.43k stars 284 forks source link

Keyword-only argument issues #1019

Open slozier opened 3 years ago

slozier commented 3 years ago

Some issues I noticed while working on https://github.com/IronLanguages/ironpython3/issues/1015. The following examples need to be run in fresh ipy instances to exhibit the broken behavior.

  1. Bad error message for missing keyword arguments:
    
    def test(*, a): return a

test() # throws TypeError: test() takes no arguments (0 given)


2. When the call binds to a failure when a value in `__kwdefaults__ ` is missing it still throws even if the value becomes available later on:
```Python
def test(*, a=1): return a

test.__kwdefaults__ = None
test() # throws TypeError as expected
test.__kwdefaults__ = {"a": 1}
assert test() == 1 # still throws the same TypeError as above
  1. Not finding a value in __kwdefaults__ should throw a TypeError instead of returning None:
    
    def test(*, a=1): return a

assert test() == 1 test.kwdefaults = None test() # should throw but returns None instead



4. PythonFunction.CalculatedCachedCompat takes into account the number of arguments in `__kwdefaults__`. I don't think this makes sense since `__kwdefaults__` can be changed any time and there's no way to know.

5. More stuff I'm forgetting about...

Related PR: https://github.com/IronLanguages/ironpython3/pull/1018
slozier commented 1 year ago

I think all but the first issue were resolved by https://github.com/IronLanguages/ironpython3/pull/1516.