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
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
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
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