Last active
May 10, 2020 23:23
-
-
Save micimize/064dc637103a6f3651b74380e0419bb2 to your computer and use it in GitHub Desktop.
arbitrary fluent interface
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 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
with tabs