Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent ParamArray and ParamDictionary parameters from binding by keyword #250

Merged
merged 2 commits into from
Nov 18, 2020

Conversation

BCSharp
Copy link
Member

@BCSharp BCSharp commented Nov 17, 2020

This fixes

import clr
clr.AddReference("rowantest.methodargs")
from Merlin.Testing.Call import VariousParameters
obj = VariousParameters()
obj.M560(1, 2, 3, z=4, b=5, c=6)

reported in #249.

Disabling by-keyword assignment to param arrays and dictionaries is controlled though a virtual method on OverloadResolver, but I stopped short from making it protected since the DLR currently cannot handle the "enabled" case so I did not want the languages to start requesting it. It can go in three ways from here:

  1. The DLR implements PositonalOnlyAttribute/NonKeywordAttribute for the benefit of all languages. Probably the best way to support it is in ReflectionUtils and the virtual extension point maybe can be abolished (i.e. preventing binding by keyword to param arrays/dictionaries will be hard-coded).
  2. PositonalOnlyAttribute/NonKeywordAttribute will be implemented at the language level (i.e. in IronPython), and the virtual extension point will become protected and overridden in PythonOverloadResolver, (or any other language-specific resolver derived from DefaultOverloadResolver, with the provision that the language can only tighten the restriction rather than relax it).
  3. The DLR will somehow be upgraded/cleaned/up/extended to be able to handle param arrays/dictionaries being bound by keyword, by some to be determined consistent set of rules. Then the virtual extension point can become protected without any restrictions.

@BCSharp
Copy link
Member Author

BCSharp commented Nov 17, 2020

After sleeping on it, I now think that option 2 is the best way forward. Implementing new attributes in IronPython 3 will allow to get the feeling how they work and possibly tweak things before releasing them to the world.

@slozier if this is OK with you, I will amend the PR accordingly.

@slozier
Copy link
Contributor

slozier commented Nov 17, 2020

if this is OK with you, I will amend the PR accordingly.

Sounds good to me!

Copy link
Contributor

@slozier slozier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Causes some failures in ipy3 but I believe they are expected.

Are you going to have to remove internal from some of the virtual methods to get PositonalOnlyAttribute/NonKeywordAttribute working from ipy3?

@BCSharp
Copy link
Member Author

BCSharp commented Nov 18, 2020

Causes some failures in ipy3 but I believe they are expected.

I have updates to ipy3 tests locally ready to go once an official DLR commit lands on master.

Are you going to have to remove internal from some of the virtual methods to get PositonalOnlyAttribute/NonKeywordAttribute working from ipy3?

No, all virtual methods I foresee needing to be overridden in PythonOverloadResolver are already protected or protected internal. I haven't looked into KeywordOnlyAttribute/NonPositionalAttribute yet so perhaps some DLR update will be needed for that, but I am parking this story for now to look into nonlocal in ipy3.

@slozier slozier merged commit d184aff into IronLanguages:master Nov 18, 2020
@BCSharp BCSharp deleted the nonkeyowrd_params branch November 18, 2020 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants