Hi Oscar,

Quoting Oscar Benjamin <oscar.j.benja...@gmail.com>:

Yes, thanks Mark. I'm not sure I've fully understood the PEP yet but I can see some parts that I definitely like. [...]

As I have just noted in my response to Mark, the aspect with the "deconstructor" (or `__match__` protocol as we called it) is definitely something that I like, too.  Moreover, I think that packages like sympy might make a strong argument for it.

That being said, perhaps we would have to start thinking about concrete use cases first and then consider how to best provide for those with an extended match protocol.  Even though I still like the idea of a flexible match method, there might be aspects that I/we overlook without knowing exactly where we want to go with this.

I'm not entirely sure but I think that with PEP 653 you can implement this like:

   def __deconstruct__(obj):
       if obj.step != 1:
           return obj.start, obj.stop, obj.step
       elif obj.start != 0:
           return obj.start, obj.stop
       else:
           return obj.stop

I think that would then mean you could use a pattern range(10) to unambiguously match range(10) without matching range(10, 20) etc.

This is certainly more of an anti-pattern (no pun intended) than an argument for the match protocol.  Shuffling positional arguments around like this seems like a rather bad idea, particularly in the context of pattern matching.  I'd rather write `case range(_, stop, _)` or `case range(0, stop, 1)` and be explicit here.

Kind regards,
Tobias

 
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/PWJSQIQ7XHJRD7ZN7QWT6HF5MGMG47GN/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to