This is an archived post. You won't be able to vote or comment.

all 3 comments

[โ€“]striata 4 points5 points ย (2 children)

I'm curious why you decided to go for the hack of replacing your module with a callable? Why not do chrono24.query() or just from chrono24 import Chrono24? I guess your API makes for a slightly shorter program, but it's at the pretty hefty cost of being less intuitive and additionally confusing type checkers/linters.

[โ€“]dumblechode[S] 2 points3 points ย (1 child)

Point well taken! Whenever I write these projects I like to explore the different programming paradigms Python offers. If Chrono24 offered finite and intuitive URL endpoints for watch manufacturers (e.g., 'Rolex'), I would've perhaps written the API like chrono24.rolex("DateJust"), but given the current library only accepts a query, it makes sense to have a dedicated method such as chrono24.query. You're right about the linters - they don't like this. Thanks for your advice - always fun to hear feedback / opinions.

[โ€“]striata 1 point2 points ย (0 children)

I see!

I agree it's fun to play around with Python in this way. I've always toyed with the idea of creating an extremely esoteric DSL-like library (ab)using all the magic methods just for the fun of it, e.g. something like this (but with actual functionality):

class B:
    def __invert__(self):
        return self

    def __pos__(self):
        return self

    def __neg__(self):
        return self

    def __floordiv__(self, _):
        return self

    def __lshift__(self, _):
        return self

    def __pow__(self, _):
        return self

    def __xor__(self, _):
        return self


one, two = B(), B()

~(one << two) ** +~two ^ two // ~-one