Created
June 27, 2023 13:17
-
-
Save jnpn/40d77bba01bc13b35d4feb667771b6d2 to your computer and use it in GitHub Desktop.
FLuent ANnotations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Flan: | |
def __init__(self, *a, **k): | |
self.a = a | |
self.k = k | |
self.chain = [] | |
def __floordiv__(self, other): | |
self.chain.append(other) | |
return self | |
def __truediv__(self, other): | |
self.chain.append(other) | |
return self | |
class lit(Flan): | |
def __repr__(self): | |
return f'<lit:{self.a}>' | |
class string(Flan): | |
def __repr__(self): | |
return f'<str:{self.a}>' | |
class num(Flan): | |
def __repr__(self): | |
return f'<int:{self.a}>' | |
def flan(f): | |
print(f.__annotations__) | |
print('maybe do load time metaprogramming here') | |
return f | |
@flan | |
def g(path: lit('api/v1') / string('name') / num('age')): | |
print(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment