Completed
Push — master ( 7962cd...0243d6 )
by Max
01:50
created

_ScopeProxy.__dir__()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
c 3
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
"""Base class for Namespace proxies in class creation."""
2
3 6
import weakref
4
5 6
from . import ops
6 6
from .proxy import _Proxy
7
8 6
_PROXY_INFOS = weakref.WeakKeyDictionary()
9
10
11 6
class _ScopeProxy(_Proxy):
12
13
    """Proxy object for manipulating namespaces during class creation."""
14
15 6
    __slots__ = '__weakref__',
16
17 6
    def __init__(self, dct, container):
18 6
        _PROXY_INFOS[self] = container
19 6
        container[self] = dct
20
21 6
    def __dir__(self):
22
        # This line will fire if dir(ns) is done during class creation.
23 6
        return _PROXY_INFOS[self][self]
24
25 6
    def __getattribute__(self, name):
26 6
        dct = _PROXY_INFOS[self][self]
27 6
        try:
28 6
            return dct[name]
29
        # These lines will fire if a non-existent namespace attribute is gotten
30
        # during class creation.
31
        except KeyError:
32
            raise AttributeError(name)
33
34 6
    def __setattr__(self, name, value):
35 6
        _PROXY_INFOS[self][self][name] = value
36
37 6
    def __delattr__(self, name):
38 6
        ops.delete(_PROXY_INFOS[self][self], name)
39
40 6
    def __enter__(self):
41 6
        return _PROXY_INFOS[self][self].__enter__()
42
43 6
    def __exit__(self, exc_type, exc_value, traceback):
44 6
        return _PROXY_INFOS[self][self].__exit__(
45
            exc_type, exc_value, traceback)
46