WARNING: The following question is asking for information concerning poor practices and dirty code. Developer discretion is advised.
Note: This is different than th
Is there anything I can do to achieve this same behavior with pickling?
Yes.
class _NoParamType(object):
def __new__(cls):
return NoParam
def __reduce__(self):
return (_NoParamType, ())
NoParam = object.__new__(_NoParamType)
To take it even further: is there anything I can do to ensure that only one instance of NoParam is ever created?
Not without writing NoParam
in C. Unless you write it in C and take advantage of C API-only capabilities, it'll always be possible to do object.__new__(type(NoParam))
to get another instance.