I use Singletons in my project (I know, I know, that's a whole other discussion), but I'm running into an issue when I try to also use one of those classes as a Fire CLI component, since it makes use or a metaclass that overrides __call__(). I believe this is messing with Fire's ability to parse the class to see which arguments are viable. Here's a simple example:
import fire
class MyMetaclass(type):
def __call__(cls, *args, **kwargs):
# This would be some generic Singleton logic...
instance = super(MyMetaclass, cls).__call__(*args, **kwargs)
return instance
class MyWithoutMetaclass:
def foo(self):
print("MyWithoutMetaclass.foo()")
class MyWithMetaclass(metaclass=MyMetaclass):
def foo(self):
print("MyWithMetaclass.foo()")
if __name__ == "__main__":
# This works
# fire.Fire(MyWithoutMetaclass)
# This fails, since it tries to pass "foo" in as an argument into the class instantiation
fire.Fire(MyWithMetaclass)
I'm sure this is because of the splatted args and kwargs in the metaclass, but this is supposed to be a generic metaclass for the entire project. Is there no clean way that I can get this to work?
I use Singletons in my project (I know, I know, that's a whole other discussion), but I'm running into an issue when I try to also use one of those classes as a Fire CLI component, since it makes use or a metaclass that overrides
__call__(). I believe this is messing with Fire's ability to parse the class to see which arguments are viable. Here's a simple example:I'm sure this is because of the splatted args and kwargs in the metaclass, but this is supposed to be a generic metaclass for the entire project. Is there no clean way that I can get this to work?