Skip to content

[BUG]: NameSpace adds arguments to classdicts #1

@typoverflow

Description

@typoverflow

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 x

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions