Skip to content

Make weakref proxies delegate comparison operators#710

Merged
slozier merged 2 commits intoIronLanguages:masterfrom
gfmcknight:master
Jan 10, 2020
Merged

Make weakref proxies delegate comparison operators#710
slozier merged 2 commits intoIronLanguages:masterfrom
gfmcknight:master

Conversation

@gfmcknight
Copy link
Copy Markdown
Contributor

Add slots for all comparison operators which delegate to the object
being proxied.

Resolves #697

Add slots for all comparison operators which delegate to the object
being proxied.
Copy link
Copy Markdown
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. Not too familiar with this part of the codebase so hopefully we're not breaking anything!

Comment thread Src/IronPython.Modules/_weakref.cs
#endregion

//[SlotField] public static PythonTypeSlot __cmp__ = new SlotWrapper(Symbols.Cmp, ProxyType);
[SlotField] public static PythonTypeSlot __eq__ = new SlotWrapper("__eq__", ProxyType);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Neat, didn't know about SlotField.

@slozier
Copy link
Copy Markdown
Contributor

slozier commented Dec 21, 2019

I finally got around to running some tests, there's a minor issue when creating a proxy of a type that doesn't have rich comparison operators. However I think it should be resolved by #709 since it'll add the operators to the object type. Will hold off on merging this PR until the other one is ready. In case you're interested here's the failure I ran into:

>>> import _weakref
>>> class A: pass
...
>>> a = A()
>>> p = _weakref.proxy(a)
>>> p.__lt__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: Operation is not valid due to the current state of the object.

@slozier
Copy link
Copy Markdown
Contributor

slozier commented Jan 10, 2020

Thanks for the PR! Will merge it in now even though #709 isn't ready.

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.

Weakref proxies should delegate comparison operators

2 participants