[issue43685] __call__ not being called on metaclass

2021-03-31 Thread Joël Larose
Joël Larose added the comment: OMG! Ok, thanks guys! Switching to super().__new__ made all the difference! I can't believe I didn't think to try to change this line. Regarding the call to cast, I know it's only for type checking. Trying to write code that works checks with mypy. I probab

[issue43685] __call__ not being called on metaclass

2021-03-31 Thread Dennis Sweeney
Dennis Sweeney added the comment: typing.cast doesn't actually do anything, it only exists as a hint for type-checkers. As William noted, using the 3-argument type(...) as you showed will only return a type, not a mcs. I think you may want super().__new__(mcs, name, bases, namespace), which

[issue43685] __call__ not being called on metaclass

2021-03-31 Thread William Pickard
William Pickard added the comment: This line is the cause of your issue: "new_cls: SingletonMeta = cast(SingletonMeta, type(name, bases, namespace))" More specifically, your call to type() actually erases all information about your meta class. If you did "type(S)", you would've seen "type" r

[issue43685] __call__ not being called on metaclass

2021-03-31 Thread Joël Larose
New submission from Joël Larose : Hi, I'm trying to implement a metaclass for the singleton pattern, with the intent of creating type-appropriate sentinels. After trying several approaches, I've come up with what I thought would be an elegant solution. However, I've run into a bit of a sna