-
Notifications
You must be signed in to change notification settings - Fork 3
Closed
Description
In NameSpaceMeta, we add arguments to classdicts and then calls type.new(cls, name, dct)
def __new__(cls, name, bases, dct):
x = type.__new__(cls, name, bases, dct)
x._data_ = {k:v for k, v in dct.items() if not _is_dunder(k) and not _is_sunder(k)}
return xHowever, suppose in a config python file we define an argument some_arg = None, and during runtime we re-assign its value to 114514, and finally we print args.some_arg, the output will still be None. This is because some_args=None will be written to the NameSpace's classdict, and the following reassignment only changes the value of args._data_["some_arg"]. When we access some_args in attribute manner (via .), this will trigger __getattribute__ and return the value None recorded in classdict, thus preventing calling __getattr__ which actually looks up some_arg in args._data_.
Metadata
Metadata
Assignees
Labels
No labels