Python builtins.__dict__() Examples
The following are 30
code examples of builtins.__dict__().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
builtins
, or try the search function
.
Example #1
Source File: test_Path.py From guppy3 with MIT License | 6 votes |
def test_type_relation(self): name = 'T' base = object bases = (base,) dict = {'__slots__': ('a', 'b')} T = type(name, bases, dict) # tp_dict can't be directly tested since .__dict__ returns a proxy # and the dict passed is not used directly. # We test it indirectly by getting a path through it. self.chkpath(T, T.a, "%s.__dict__['a']") # The C-struct __slots__ field can't be tested directly # This just tests the ordinary attribute self.chkpath(T, T.__slots__, "%s.__dict__['__slots__']") self.chkrelattr(T, '__mro__', '__base__', '__bases__') # tp_cache and tp_subclasses can also not be tested directly # Inheritance is tested via test_object_relation()
Example #2
Source File: inspect.py From jawfish with MIT License | 6 votes |
def getmembers(object, predicate=None): """Return all members of an object as (name, value) pairs sorted by name. Optionally, only return members that satisfy a given predicate.""" if isclass(object): mro = (object,) + getmro(object) else: mro = () results = [] for key in dir(object): # First try to get the value via __dict__. Some descriptors don't # like calling their __get__ (see bug #1785). for base in mro: if key in base.__dict__: value = base.__dict__[key] break else: try: value = getattr(object, key) except AttributeError: continue if not predicate or predicate(value): results.append((key, value)) results.sort() return results
Example #3
Source File: rlcompleter.py From scylla with Apache License 2.0 | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] seen = {"__builtins__"} n = len(text) for word in keyword.kwlist: if word[:n] == text: seen.add(word) matches.append(word) for nspace in [self.namespace, builtins.__dict__]: for word, val in nspace.items(): if word[:n] == text and word not in seen: seen.add(word) matches.append(self._callable_postfix(val, word)) return matches
Example #4
Source File: rlcompleter.py From kobo-predict with BSD 2-Clause "Simplified" License | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] seen = {"__builtins__"} n = len(text) for word in keyword.kwlist: if word[:n] == text: seen.add(word) matches.append(word) for nspace in [self.namespace, builtins.__dict__]: for word, val in nspace.items(): if word[:n] == text and word not in seen: seen.add(word) matches.append(self._callable_postfix(val, word)) return matches
Example #5
Source File: stats.py From teleport with Apache License 2.0 | 6 votes |
def __init__(self): super().__init__() import builtins if '__tp_stats__' in builtins.__dict__: raise RuntimeError('TPStats object exists, you can not create more than one instance.') # 实时数据我们在内存中保留最近10分钟的数据,每5秒收集一次,共 10*60/5 = 120 条记录 self._sys_stats = list() # 网络流量和磁盘IO是递增的数据,因此要记下上一次采集的数据,以便计算间隔时间内的增量 self._net_recv = 0 self._net_sent = 0 self._disk_read = 0 self._disk_write = 0 self._counter_stats = { 'user': 1, 'host': 0, 'acc': 0, 'conn': 0 }
Example #6
Source File: inspect.py From Imogen with MIT License | 6 votes |
def isabstract(object): """Return true if the object is an abstract base class (ABC).""" if not isinstance(object, type): return False if object.__flags__ & TPFLAGS_IS_ABSTRACT: return True if not issubclass(type(object), abc.ABCMeta): return False if hasattr(object, '__abstractmethods__'): # It looks like ABCMeta.__new__ has finished running; # TPFLAGS_IS_ABSTRACT should have been accurate. return False # It looks like ABCMeta.__new__ has not finished running yet; we're # probably in __init_subclass__. We'll look for abstractmethods manually. for name, value in object.__dict__.items(): if getattr(value, "__isabstractmethod__", False): return True for base in object.__bases__: for name in getattr(base, "__abstractmethods__", ()): value = getattr(object, name, None) if getattr(value, "__isabstractmethod__", False): return True return False
Example #7
Source File: rlcompleter.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] n = len(text) for word in keyword.kwlist: if word[:n] == text: matches.append(word) for nspace in [builtins.__dict__, self.namespace]: for word, val in nspace.items(): if word[:n] == text and word != "__builtins__": matches.append(self._callable_postfix(val, word)) return matches
Example #8
Source File: _analyze.py From myhdl with GNU Lesser General Public License v2.1 | 6 votes |
def _analyzeTopFunc(func, *args, **kwargs): tree = _makeAST(func) v = _AnalyzeTopFuncVisitor(func, tree, *args, **kwargs) v.visit(tree) objs = [] for name, obj in v.fullargdict.items(): if not isinstance(obj, _Signal): objs.append((name, obj)) # create ports for any signal in the top instance if it was buried in an # object passed as in argument # now expand the interface objects for name, obj in objs: if hasattr(obj, '__dict__'): # must be an interface object (probably ...?) expandinterface(v, name, obj) return v
Example #9
Source File: rlcompleter.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def complete(self, text, state): """Return the next possible completion for 'text'. This is called successively with state == 0, 1, 2, ... until it returns None. The completion should begin with 'text'. """ if self.use_main_ns: self.namespace = __main__.__dict__ if not text.strip(): if state == 0: return '\t' else: return None if state == 0: if "." in text: self.matches = self.attr_matches(text) else: self.matches = self.global_matches(text) try: return self.matches[state] except IndexError: return None
Example #10
Source File: run.py From bootstrap.pytorch with BSD 3-Clause "New" or "Revised" License | 6 votes |
def activate_profiler(): if sys.version_info[0] == 3: # PY3 import builtins else: import __builtin__ as builtins if Options()['misc'].get('profile', False): # if profiler is activated, associate line_profiler Logger()('Activating line_profiler...') try: import line_profiler except ModuleNotFoundError: Logger()('Failed to import line_profiler.', log_level=Logger.ERROR, raise_error=False) Logger()('Please install it from https://github.com/rkern/line_profiler', log_level=Logger.ERROR, raise_error=False) return prof = line_profiler.LineProfiler() builtins.__dict__['profile'] = prof else: # otherwise, create a blank profiler, to disable profiling code builtins.__dict__['profile'] = lambda func: func prof = None return prof
Example #11
Source File: db.py From teleport with Apache License 2.0 | 6 votes |
def __init__(self): if '__teleport_db__' in builtins.__dict__: raise RuntimeError('TPDatabase object exists, you can not create more than one instance.') self.db_type = self.DB_TYPE_UNKNOWN self.sqlite_file = '' self.mysql_host = '' self.mysql_port = 0 self.mysql_db = '' self.mysql_user = '' self.mysql_password = '' self.connected = False # 数据库是否已经连接上了 self.need_create = False # 数据尚未存在,需要创建 self.need_upgrade = False # 数据库已存在但版本较低,需要升级 self.current_ver = 0 self.auto_increment = '' self.place_holder = '' self._table_prefix = '' self._conn_pool = None
Example #12
Source File: start.py From RAFCON with Eclipse Public License 1.0 | 6 votes |
def setup_environment(): """Ensures that the environmental variable RAFCON_LIB_PATH is existent """ # The RAFCON_LIB_PATH points to a path with common RAFCON libraries # If the env variable is not set, we have to determine it. if not os.environ.get('RAFCON_LIB_PATH', None): rafcon_library_path = resources.get_data_file_path("rafcon", "libraries") if rafcon_library_path: os.environ['RAFCON_LIB_PATH'] = rafcon_library_path else: logger.warning("Could not find root directory of RAFCON libraries. Please specify manually using the " "env var RAFCON_LIB_PATH") # Install dummy _ builtin function in case i18.setup_l10n() is not called if sys.version_info >= (3,): import builtins as builtins23 else: import __builtin__ as builtins23 if "_" not in builtins23.__dict__: builtins23.__dict__["_"] = lambda s: s
Example #13
Source File: _analyze.py From myhdl with GNU Lesser General Public License v2.1 | 5 votes |
def expandinterface(v, name, obj): for attr, attrobj in vars(obj).items(): if isinstance(attrobj, _Signal): signame = attrobj._name if not signame: signame = name + '_' + attr attrobj._name = signame v.argdict[signame] = attrobj v.argnames.append(signame) elif isinstance(attrobj, myhdl.EnumType): pass elif hasattr(attrobj, '__dict__'): # can assume is yet another interface ... expandinterface(v, name + '_' + attr, attrobj)
Example #14
Source File: inspect.py From Imogen with MIT License | 5 votes |
def _static_getmro(klass): return type.__dict__['__mro__'].__get__(klass)
Example #15
Source File: rlcompleter.py From Imogen with MIT License | 5 votes |
def __init__(self, namespace = None): """Create a new completer for the command line. Completer([namespace]) -> completer instance. If unspecified, the default namespace where completions are performed is __main__ (technically, __main__.__dict__). Namespaces should be given as dictionaries. Completer instances should be used as the completion mechanism of readline via the set_completer() call: readline.set_completer(Completer(my_namespace).complete) """ if namespace and not isinstance(namespace, dict): raise TypeError('namespace must be a dictionary') # Don't bind to namespace quite yet, but flag whether the user wants a # specific namespace or to use __main__.__dict__. This will allow us # to bind to __main__.__dict__ at completion time, not now. if namespace is None: self.use_main_ns = 1 else: self.use_main_ns = 0 self.namespace = namespace
Example #16
Source File: inspect.py From Imogen with MIT License | 5 votes |
def _shadowed_dict(klass): dict_attr = type.__dict__["__dict__"] for entry in _static_getmro(klass): try: class_dict = dict_attr.__get__(entry)["__dict__"] except KeyError: pass else: if not (type(class_dict) is types.GetSetDescriptorType and class_dict.__name__ == "__dict__" and class_dict.__objclass__ is entry): return class_dict return _sentinel
Example #17
Source File: inspect.py From Imogen with MIT License | 5 votes |
def _check_class(klass, attr): for entry in _static_getmro(klass): if _shadowed_dict(type(entry)) is _sentinel: try: return entry.__dict__[attr] except KeyError: pass return _sentinel
Example #18
Source File: memory_profiler.py From pyFileFixity with MIT License | 5 votes |
def __call__(self, func): self.add_function(func) f = self.wrap_function(func) f.__module__ = func.__module__ f.__name__ = func.__name__ f.__doc__ = func.__doc__ f.__dict__.update(getattr(func, '__dict__', {})) return f
Example #19
Source File: memory_profiler.py From pyFileFixity with MIT License | 5 votes |
def __call__(self, func): if not hasattr(func, "__call__"): raise ValueError("Value must be callable") self.add_function(func) f = self.wrap_function(func) f.__module__ = func.__module__ f.__name__ = func.__name__ f.__doc__ = func.__doc__ f.__dict__.update(getattr(func, '__dict__', {})) return f
Example #20
Source File: memory_profiler.py From pyFileFixity with MIT License | 5 votes |
def run(self, cmd): """ Profile a single executable statment in the main namespace. """ import __main__ dict = __main__.__dict__ return self.runctx(cmd, dict, dict)
Example #21
Source File: memory_profiler.py From pyFileFixity with MIT License | 5 votes |
def __call__(self, func): self.add_function(func) f = self.wrap_function(func) f.__module__ = func.__module__ f.__name__ = func.__name__ f.__doc__ = func.__doc__ f.__dict__.update(getattr(func, '__dict__', {})) return f
Example #22
Source File: inspect.py From ironpython3 with Apache License 2.0 | 5 votes |
def _check_instance(obj, attr): instance_dict = {} try: instance_dict = object.__getattribute__(obj, "__dict__") except AttributeError: pass return dict.get(instance_dict, attr, _sentinel)
Example #23
Source File: inspect.py From ironpython3 with Apache License 2.0 | 5 votes |
def _shadowed_dict(klass): dict_attr = type.__dict__["__dict__"] for entry in _static_getmro(klass): try: class_dict = dict_attr.__get__(entry)["__dict__"] except KeyError: pass else: if not (type(class_dict) is types.GetSetDescriptorType and class_dict.__name__ == "__dict__" and class_dict.__objclass__ is entry): return class_dict return _sentinel
Example #24
Source File: rlcompleter.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def __init__(self, namespace = None): """Create a new completer for the command line. Completer([namespace]) -> completer instance. If unspecified, the default namespace where completions are performed is __main__ (technically, __main__.__dict__). Namespaces should be given as dictionaries. Completer instances should be used as the completion mechanism of readline via the set_completer() call: readline.set_completer(Completer(my_namespace).complete) """ if namespace and not isinstance(namespace, dict): raise TypeError('namespace must be a dictionary') # Don't bind to namespace quite yet, but flag whether the user wants a # specific namespace or to use __main__.__dict__. This will allow us # to bind to __main__.__dict__ at completion time, not now. if namespace is None: self.use_main_ns = 1 else: self.use_main_ns = 0 self.namespace = namespace
Example #25
Source File: inspect.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def _shadowed_dict(klass): dict_attr = type.__dict__["__dict__"] for entry in _static_getmro(klass): try: class_dict = dict_attr.__get__(entry)["__dict__"] except KeyError: pass else: if not (type(class_dict) is types.GetSetDescriptorType and class_dict.__name__ == "__dict__" and class_dict.__objclass__ is entry): return class_dict return _sentinel
Example #26
Source File: inspect.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def _check_instance(obj, attr): instance_dict = {} try: instance_dict = object.__getattribute__(obj, "__dict__") except AttributeError: pass return dict.get(instance_dict, attr, _sentinel)
Example #27
Source File: inspect.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def _static_getmro(klass): return type.__dict__['__mro__'].__get__(klass)
Example #28
Source File: rlcompleter.py From ironpython3 with Apache License 2.0 | 5 votes |
def __init__(self, namespace = None): """Create a new completer for the command line. Completer([namespace]) -> completer instance. If unspecified, the default namespace where completions are performed is __main__ (technically, __main__.__dict__). Namespaces should be given as dictionaries. Completer instances should be used as the completion mechanism of readline via the set_completer() call: readline.set_completer(Completer(my_namespace).complete) """ if namespace and not isinstance(namespace, dict): raise TypeError('namespace must be a dictionary') # Don't bind to namespace quite yet, but flag whether the user wants a # specific namespace or to use __main__.__dict__. This will allow us # to bind to __main__.__dict__ at completion time, not now. if namespace is None: self.use_main_ns = 1 else: self.use_main_ns = 0 self.namespace = namespace
Example #29
Source File: gettext.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def install(self, names=None): import builtins builtins.__dict__['_'] = self.gettext if hasattr(names, "__contains__"): if "gettext" in names: builtins.__dict__['gettext'] = builtins.__dict__['_'] if "ngettext" in names: builtins.__dict__['ngettext'] = self.ngettext if "lgettext" in names: builtins.__dict__['lgettext'] = self.lgettext if "lngettext" in names: builtins.__dict__['lngettext'] = self.lngettext
Example #30
Source File: memory_profiler.py From pyFileFixity with MIT License | 5 votes |
def run(self, cmd): """ Profile a single executable statement in the main namespace. """ # TODO: can this be removed ? import __main__ main_dict = __main__.__dict__ return self.runctx(cmd, main_dict, main_dict)