Completed
Push — master ( 35a3ad...c78511 )
by Max
02:21
created

_owner()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 2
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
_NAMESPACES = weakref.WeakKeyDictionary()
9 6
_OWNERS = weakref.WeakKeyDictionary()
10
11
12 6
def _ns(self):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
13 6
    return _owner(self).proxies[self]
14
15
16 6
def _owner(self):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
17 6
    return _OWNERS[self]
18
19
20 6
class _ScopeProxy(_Proxy):
21
22
    """Proxy object for manipulating namespaces during class creation."""
23
24 6
    __slots__ = '__weakref__',
25
26 6
    def __init__(self, dct, owner):
27 6
        _OWNERS[self] = owner
28 6
        owner.proxies[self] = dct
29
30 6
    def __dir__(self):
31
        # This line will fire if dir(ns) is done during class creation.
32 6
        return _ns(self)
33
34 6
    def __getattribute__(self, name):
35 6
        dct = _ns(self)
36 6
        try:
37 6
            value = dct[name]
38
        # These lines will fire if a non-existent namespace attribute is gotten
39
        # during class creation.
40 6
        except KeyError:
41 6
            raise AttributeError(name)
42 6
        return _owner(self).wrap(value)
43
44 6
    def __setattr__(self, name, value):
45 6
        _ns(self)[name] = value
46
47 6
    def __delattr__(self, name):
48 6
        ops.delete(_ns(self), name)
49
50 6
    def __enter__(self):
51 6
        return _ns(self).__enter__()
52
53 6
    def __exit__(self, exc_type, exc_value, traceback):
54
        return _ns(self).__exit__(exc_type, exc_value, traceback)
55