Re:Brython – A Python 3 implementation for client-side web p...
by stoksc on Monday July 06, 2020 @09:18AM
(#23747552)
Yeah, overloading to build a little dsl over some objects sort of is something I’ve seen a lot. See airflow:
https://stackoverflow.com/questions/52389105/how-operator-de...
When it’s used that way, you’ve lost that the operation is semantically analogous to __le__. I think the assumption it has no side effects goes, too.
Edit: not saying I like it, though.
Re:Brython – A Python 3 implementation for client-side web p...
by duckerude on Monday July 06, 2020 @09:48AM
(#23747800)
Overloading comparison operators like this is a particularly bad idea in Python, because of the "smart" behavior they have baked in. Overloading >> is comparatively safe.
Unless you implement __ge__, `'Hello!' >= document` will also call __le__, which may or may not be what you want. And `'Hello!' >= document <= 10` is equivalent to `'Hello!' >= document and document <= 10`, which can lead to confusing surprises.
(Brython does implement all of those pitfalls faithfully)
Re:Brython – A Python 3 implementation for client-side web p...
by linkdd on Monday July 06, 2020 @09:03AM
(#23747423)
Sorry, what I meant was: Is it the Python you want in your browser?
So, this is just another implementation with its tradeoffs, just like when using Jython to have Python (without its ecosystem) and the JVM. Here you have Python with another semantic to learn.
Re:Brython – A Python 3 implementation for client-side web p...
by VectorLock on Monday July 06, 2020 @09:20AM
(#23747567)
I see this happening in a lot of Python libraries. It's still Python - or *ython maybe we can call it. The idiom of cutesy operator overloaded spread in from other languages; I'm personally not a fan.
It may not be "pythonic", but there's an established tradition of operator methods and there's no requirement that python code conform to any particular tradition.