Skip to content

Instantly share code, notes, and snippets.

@micimize
Last active May 10, 2020 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micimize/064dc637103a6f3651b74380e0419bb2 to your computer and use it in GitHub Desktop.
Save micimize/064dc637103a6f3651b74380e0419bb2 to your computer and use it in GitHub Desktop.
arbitrary fluent interface
class FluentMeta(type):
def __getattr__(cls, ignore):
return cls()
def __getitem__(cls, ignore):
return cls()
class Fluent(metaclass=FluentMeta):
def __getattr__(self, ignore):
return self
def __getitem__(self, ignore):
return self
def __call__(self, data):
return data
Fluent.interfaces.are_sometimes_used[
'like arbitrary inline docs, '
].so.why_not.make.them.completely('arbitrary?')
#=> 'arbitrary?'
to = Fluent
Fluent.ly.expect(lambda x: x + 1)(to['return'][2].when.passed(1)) == 2
#=> True
@micimize
Copy link
Author

micimize commented May 10, 2020

with tabs

class FluentMeta(type):

	def __getattr__(cls, ignore):
		return cls()

	def __getitem__(cls, ignore):
		return cls()

class Fluent(metaclass=FluentMeta):

	def __getattr__(self, ignore):
		return self

	def __getitem__(self, ignore):
		return self

	def __call__(self, data):
		return data

Fluent.interfaces.are_sometimes_used[
		'like arbitrary inline docs, '
		].so.why_not.make.them.completely('arbitrary?')
#=> 'arbitrary?'

to = Fluent
Fluent.ly.expect(lambda x: x + 1)(to['return'][2].when.passed(1)) == 2
#=> True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment