The Singleton meta class unexpectedly raises a TypeError when we thought __instance__ existed
zancas opened this issue · 4 comments
In [4]: _RcliConfig.call()
TypeError Traceback (most recent call last)
in ()
----> 1 _RcliConfig.call()
~/rcli/venv/lib/python3.6/site-packages/typet/meta.py in call(cls, args, **kwargs)
78 else:
79 try:
---> 80 cls.instance.singleton(args, **kwargs) # type: ignore
81 except AttributeError:
82 pass
TypeError: 'NoneType' object is not callable
The code in question is here:
https://github.com/contains-io/typet/blob/master/typet/meta.py#L64
Is this fixed with the catch for TypeError
?
I still don't understand where the TypeError
in question is being raised.
The issue is that __instance__
defaults to None
. The if-statement
checks for falsey then tries to run it, but then it tries to call __singleton__
on __instance__
which is None
. Maybe a better idea would be to change that else to elif cls.__instance__ is not None:
instead of catching TypeError
.
I think this is fine with the TypeError
check. Closing this for now.