for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
"""Base class for Namespace proxies in class creation."""
import weakref
from . import ops
from .proxy import _Proxy
_NAMESPACES = weakref.WeakKeyDictionary()
_OWNERS = weakref.WeakKeyDictionary()
def _ns(self):
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.
return _owner(self).proxies[self]
def _owner(self):
return _OWNERS[self]
class _ScopeProxy(_Proxy):
"""Proxy object for manipulating namespaces during class creation."""
__slots__ = '__weakref__',
def __init__(self, dct, owner):
_OWNERS[self] = owner
owner.proxies[self] = dct
def __dir__(self):
# This line will fire if dir(ns) is done during class creation.
return _ns(self)
def __getattribute__(self, name):
dct = _ns(self)
try:
value = dct[name]
# These lines will fire if a non-existent namespace attribute is gotten
# during class creation.
except KeyError:
raise AttributeError(name)
return _owner(self).wrap(value)
def __setattr__(self, name, value):
_ns(self)[name] = value
def __delattr__(self, name):
ops.delete(_ns(self), name)
def __enter__(self):
return _ns(self).__enter__()
def __exit__(self, exc_type, exc_value, traceback):
return _ns(self).__exit__(exc_type, exc_value, traceback)
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.