Skip to content

Instantly share code, notes, and snippets.

@jnpn
Created June 27, 2023 13:17
Show Gist options
  • Save jnpn/40d77bba01bc13b35d4feb667771b6d2 to your computer and use it in GitHub Desktop.
Save jnpn/40d77bba01bc13b35d4feb667771b6d2 to your computer and use it in GitHub Desktop.
FLuent ANnotations
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