aboutsummaryrefslogtreecommitdiffstats
path: root/tools/namespace.py
blob: 2811decb384197c7299a5a52998b905a0611b7c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Copyright (C) 2021 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

class Namespace(object):
    """Inheriting this class enables property-style 'object.attr'
    access to member attributes instead of relying on dict-style
    'object[attr]' and '.get(attr)' accessors.
    """

    def __init__(self, **kwargs):
        self.__dict__.update(kwargs)

    @property  # For use when serializing, to dump back to JSON
    def as_map(self):
        return self.__dict__

    def __repr__(self):
        return str(self.as_map)