Special Method Protocols

__getnewargs_ex__() — serialization protocol

Supply positional and keyword arguments for __new__ during reconstruction under pickle protocols 2 and newer (protocols 2/3 use this hook since 3.6). Useful for keyword-only constructors.

Formal Syntax & Structure

python syntaxpython
def __getnewargs_ex__(self):

Return Value

tuple[tuple, dict]

Positional arguments and keyword dictionary.

Working Example

Example Snippetpython
import copyclass Label(str):    def __new__(cls, *, value): return super().__new__(cls,value.upper())    def __getnewargs_ex__(self): return (), {"value":str(self)}print(str(copy.copy(Label(value="ready"))))
Python Reference