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

Pattern match ANY and python sets #4

Open
mkmik opened this issue Dec 3, 2012 · 2 comments
Open

Pattern match ANY and python sets #4

mkmik opened this issue Dec 3, 2012 · 2 comments
Labels

Comments

@mkmik
Copy link
Collaborator

mkmik commented Dec 3, 2012

It appears that sets are not correctly matched by ANY:

class Node(Actor):
    def pre_start(self):
        self << ('test', set([1,2,3]))

    def receive(self, msg):
        if msg == ('test', ANY):
            dbg("Got a set", msg)
        else:
            dbg("unhandled msg", msg)

This test prints out "unhandled msg, ('test', set([1,2,3]))"

@erikkaplun
Copy link
Owner

This is a known issue and hard to fix:

In [1]: from spinoff.util.pattern_matching import ANY

In [2]: ANY == set([])
Out[2]: True

In [3]: ANY == set([1, 2, 3])
Out[3]: True

In [4]: ('test', ANY) == ('test', set([1, 2, 3]))
Out[4]: True

In [5]: ('test', set([1, 2, 3])) == ('test', ANY)
Out[5]: False

In [6]: set([1, 2, 3]) == ANY
Out[6]: False

The reason is that it is Python who decides which operand's __eq__ method gets invoked.

@erikkaplun
Copy link
Owner

I think the proper solution for this is not to rely on ==—using == could be considered unpythonic anyway. Metacontext however could solve this easily—talking of which, I still haven't had time to look into it...

I should definitely address this issue before Spinoff 1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants