Giter Site home page Giter Site logo

function-pattern-matching's People

Contributors

rasguanabana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

function-pattern-matching's Issues

Mixing case and guard raises error

Works:

@fpm.case
@fpm.guard(msg = fpm.eq("Ping"), sender = fpm.isoftype(Actor))
def handle(self, sender, msg, payload):
	sender.tell("Pong", sender=self)

Doesn't work:

@fpm.case(msg = "Ping")
@fpm.guard(sender = fpm.isoftype(Actor))
def handle(self, sender, msg, payload):
	sender.tell("Pong", sender=self)

The second case raises the following error:

Traceback (most recent call last):
  File "./ping_pong.py", line 14, in <module>
    class PingPong(Actor):
  File "./ping_pong.py", line 20, in PingPong
    @fpm.guard(sender = fpm.isoftype(Actor))
  File "/Users/mklemm/compile/python-arago-actors/lib/python3.7/site-packages/function_pattern_matching.py", line 551, in decorator
    decoratee._argument_guards[arg_name] = match & decoratee._argument_guards[arg_name]
  File "/Users/mklemm/compile/python-arago-actors/lib/python3.7/site-packages/function_pattern_matching.py", line 141, in checks
    raise TypeError("The right-hand operand has to be instance of GuardFunc")
TypeError: The right-hand operand has to be instance of GuardFunc

Doesn't work with methods

Hi,

I'm writing a small actor system based on gevent and I really like your pattern matching library. It allows me keep the functions that handle the various messages that can be sent to an actor rather short because of the multi-dispatch feature.

But there seems to be a problem when decorating methods instead of functions with @guard and @case: Because inspect.signature skips the "self" argument, the signature doesn't match and a MatchError is raised

My current workaround is this:

from function_pattern_matching import MultiFunc

if isinstance(obj.method, MultiFunc):
    obj.method(obj, argument)
else:
    obj.method(argument)

It works and isn't too bad but I wonder if you have an idea howto improve this.

But anyway, thanks for the great work!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.