Direct dict object modification High

Modifying object.__dict__ directly or writing to an instance of a class __dict__ attribute directly is not recommended. Inside every module is a __dict__ attribute which contains its symbol table. If you modify object.__dict__, then the symbol table is changed. Also, direct assignment to the __dict__ attribute is not possible.

Detector ID
Common Weakness Enumeration (CWE) external icon

Noncompliant example

1def modify_dictionary_noncompliant():
2    import os
3    # Noncompliant: modifies the __dict__ object directly.
4    os.__dict__ = value

Compliant example

1def modify_dictionary_compliant(test_args):
2    from nettles_service.models.baseline import Baseline
4    baseline = Baseline(**test_args)
5    for arg, value in test_args.items():
6        # Compliant: avoids modifying the __dict__ object directly.
7        assert baseline.__dict__[arg] == value