Python warnings.py() Examples
The following are 11
code examples of warnings.py().
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
warnings
, or try the search function
.
Example #1
Source File: langhelpers.py From jbox with MIT License | 5 votes |
def monkeypatch_proxied_specials(into_cls, from_cls, skip=None, only=None, name='self.proxy', from_instance=None): """Automates delegation of __specials__ for a proxying type.""" if only: dunders = only else: if skip is None: skip = ('__slots__', '__del__', '__getattribute__', '__metaclass__', '__getstate__', '__setstate__') dunders = [m for m in dir(from_cls) if (m.startswith('__') and m.endswith('__') and not hasattr(into_cls, m) and m not in skip)] for method in dunders: try: fn = getattr(from_cls, method) if not hasattr(fn, '__call__'): continue fn = getattr(fn, 'im_func', fn) except AttributeError: continue try: spec = compat.inspect_getargspec(fn) fn_args = inspect.formatargspec(spec[0]) d_args = inspect.formatargspec(spec[0][1:]) except TypeError: fn_args = '(self, *args, **kw)' d_args = '(*args, **kw)' py = ("def %(method)s%(fn_args)s: " "return %(name)s.%(method)s%(d_args)s" % locals()) env = from_instance is not None and {name: from_instance} or {} compat.exec_(py, env) try: env[method].__defaults__ = fn.__defaults__ except AttributeError: pass setattr(into_cls, method, env[method])
Example #2
Source File: langhelpers.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def monkeypatch_proxied_specials(into_cls, from_cls, skip=None, only=None, name='self.proxy', from_instance=None): """Automates delegation of __specials__ for a proxying type.""" if only: dunders = only else: if skip is None: skip = ('__slots__', '__del__', '__getattribute__', '__metaclass__', '__getstate__', '__setstate__') dunders = [m for m in dir(from_cls) if (m.startswith('__') and m.endswith('__') and not hasattr(into_cls, m) and m not in skip)] for method in dunders: try: fn = getattr(from_cls, method) if not hasattr(fn, '__call__'): continue fn = getattr(fn, 'im_func', fn) except AttributeError: continue try: spec = compat.inspect_getargspec(fn) fn_args = inspect.formatargspec(spec[0]) d_args = inspect.formatargspec(spec[0][1:]) except TypeError: fn_args = '(self, *args, **kw)' d_args = '(*args, **kw)' py = ("def %(method)s%(fn_args)s: " "return %(name)s.%(method)s%(d_args)s" % locals()) env = from_instance is not None and {name: from_instance} or {} compat.exec_(py, env) try: env[method].__defaults__ = fn.__defaults__ except AttributeError: pass setattr(into_cls, method, env[method])
Example #3
Source File: langhelpers.py From planespotter with MIT License | 5 votes |
def monkeypatch_proxied_specials(into_cls, from_cls, skip=None, only=None, name='self.proxy', from_instance=None): """Automates delegation of __specials__ for a proxying type.""" if only: dunders = only else: if skip is None: skip = ('__slots__', '__del__', '__getattribute__', '__metaclass__', '__getstate__', '__setstate__') dunders = [m for m in dir(from_cls) if (m.startswith('__') and m.endswith('__') and not hasattr(into_cls, m) and m not in skip)] for method in dunders: try: fn = getattr(from_cls, method) if not hasattr(fn, '__call__'): continue fn = getattr(fn, 'im_func', fn) except AttributeError: continue try: spec = compat.inspect_getargspec(fn) fn_args = inspect.formatargspec(spec[0]) d_args = inspect.formatargspec(spec[0][1:]) except TypeError: fn_args = '(self, *args, **kw)' d_args = '(*args, **kw)' py = ("def %(method)s%(fn_args)s: " "return %(name)s.%(method)s%(d_args)s" % locals()) env = from_instance is not None and {name: from_instance} or {} compat.exec_(py, env) try: env[method].__defaults__ = fn.__defaults__ except AttributeError: pass setattr(into_cls, method, env[method])
Example #4
Source File: langhelpers.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def monkeypatch_proxied_specials(into_cls, from_cls, skip=None, only=None, name='self.proxy', from_instance=None): """Automates delegation of __specials__ for a proxying type.""" if only: dunders = only else: if skip is None: skip = ('__slots__', '__del__', '__getattribute__', '__metaclass__', '__getstate__', '__setstate__') dunders = [m for m in dir(from_cls) if (m.startswith('__') and m.endswith('__') and not hasattr(into_cls, m) and m not in skip)] for method in dunders: try: fn = getattr(from_cls, method) if not hasattr(fn, '__call__'): continue fn = getattr(fn, 'im_func', fn) except AttributeError: continue try: spec = compat.inspect_getargspec(fn) fn_args = inspect.formatargspec(spec[0]) d_args = inspect.formatargspec(spec[0][1:]) except TypeError: fn_args = '(self, *args, **kw)' d_args = '(*args, **kw)' py = ("def %(method)s%(fn_args)s: " "return %(name)s.%(method)s%(d_args)s" % locals()) env = from_instance is not None and {name: from_instance} or {} compat.exec_(py, env) try: env[method].__defaults__ = fn.__defaults__ except AttributeError: pass setattr(into_cls, method, env[method])
Example #5
Source File: langhelpers.py From jarvis with GNU General Public License v2.0 | 5 votes |
def monkeypatch_proxied_specials(into_cls, from_cls, skip=None, only=None, name='self.proxy', from_instance=None): """Automates delegation of __specials__ for a proxying type.""" if only: dunders = only else: if skip is None: skip = ('__slots__', '__del__', '__getattribute__', '__metaclass__', '__getstate__', '__setstate__') dunders = [m for m in dir(from_cls) if (m.startswith('__') and m.endswith('__') and not hasattr(into_cls, m) and m not in skip)] for method in dunders: try: fn = getattr(from_cls, method) if not hasattr(fn, '__call__'): continue fn = getattr(fn, 'im_func', fn) except AttributeError: continue try: spec = compat.inspect_getargspec(fn) fn_args = inspect.formatargspec(spec[0]) d_args = inspect.formatargspec(spec[0][1:]) except TypeError: fn_args = '(self, *args, **kw)' d_args = '(*args, **kw)' py = ("def %(method)s%(fn_args)s: " "return %(name)s.%(method)s%(d_args)s" % locals()) env = from_instance is not None and {name: from_instance} or {} compat.exec_(py, env) try: env[method].__defaults__ = fn.__defaults__ except AttributeError: pass setattr(into_cls, method, env[method])
Example #6
Source File: langhelpers.py From android_universal with MIT License | 5 votes |
def monkeypatch_proxied_specials(into_cls, from_cls, skip=None, only=None, name='self.proxy', from_instance=None): """Automates delegation of __specials__ for a proxying type.""" if only: dunders = only else: if skip is None: skip = ('__slots__', '__del__', '__getattribute__', '__metaclass__', '__getstate__', '__setstate__') dunders = [m for m in dir(from_cls) if (m.startswith('__') and m.endswith('__') and not hasattr(into_cls, m) and m not in skip)] for method in dunders: try: fn = getattr(from_cls, method) if not hasattr(fn, '__call__'): continue fn = getattr(fn, 'im_func', fn) except AttributeError: continue try: spec = compat.inspect_getargspec(fn) fn_args = compat.inspect_formatargspec(spec[0]) d_args = compat.inspect_formatargspec(spec[0][1:]) except TypeError: fn_args = '(self, *args, **kw)' d_args = '(*args, **kw)' py = ("def %(method)s%(fn_args)s: " "return %(name)s.%(method)s%(d_args)s" % locals()) env = from_instance is not None and {name: from_instance} or {} compat.exec_(py, env) try: env[method].__defaults__ = fn.__defaults__ except AttributeError: pass setattr(into_cls, method, env[method])
Example #7
Source File: warn.py From integrations-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
def warning(message): # We disable caching of this helper so it can be used multiple times. # https://github.com/python/cpython/blob/9a4758550d96030ee7e7f7c7c68b435db1a2a825/Lib/warnings.py#L362 with warnings.catch_warnings(): warnings.warn(message, stacklevel=2)
Example #8
Source File: warn.py From integrations-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _formatwarning(message, category, filename, lineno, line=None): # Shorten output for occurrences during E2E to just what is necessary for a nice display. if e2e_active(): return '{}\n'.format(message) return _original_formatwarning(message, category, filename, lineno, line=line) # We can't override `showwarning` as usual because pytest already overrides that for logs. # https://github.com/pytest-dev/pytest/blob/b76104e722f41ce367765cd988ee8314d45b20b5/src/_pytest/warnings.py#L75
Example #9
Source File: gen_rst.py From sphinx-gallery with BSD 3-Clause "New" or "Revised" License | 4 votes |
def generate_dir_rst(src_dir, target_dir, gallery_conf, seen_backrefs): """Generate the gallery reStructuredText for an example directory.""" head_ref = os.path.relpath(target_dir, gallery_conf['src_dir']) fhindex = """\n\n.. _sphx_glr_{0}:\n\n""".format( head_ref.replace(os.path.sep, '_')) fname = _get_readme(src_dir, gallery_conf) with codecs.open(fname, 'r', encoding='utf-8') as fid: fhindex += fid.read() # Add empty lines to avoid bug in issue #165 fhindex += "\n\n" if not os.path.exists(target_dir): os.makedirs(target_dir) # get filenames listdir = [fname for fname in os.listdir(src_dir) if fname.endswith('.py')] # limit which to look at based on regex (similar to filename_pattern) listdir = [fname for fname in listdir if re.search(gallery_conf['ignore_pattern'], os.path.normpath(os.path.join(src_dir, fname))) is None] # sort them sorted_listdir = sorted( listdir, key=gallery_conf['within_subsection_order'](src_dir)) entries_text = [] costs = [] build_target_dir = os.path.relpath(target_dir, gallery_conf['src_dir']) iterator = sphinx_compatibility.status_iterator( sorted_listdir, 'generating gallery for %s... ' % build_target_dir, length=len(sorted_listdir)) for fname in iterator: intro, title, cost = generate_file_rst( fname, target_dir, src_dir, gallery_conf, seen_backrefs) src_file = os.path.normpath(os.path.join(src_dir, fname)) costs.append((cost, src_file)) this_entry = _thumbnail_div(target_dir, gallery_conf['src_dir'], fname, intro, title) + """ .. toctree:: :hidden: /%s\n""" % os.path.join(build_target_dir, fname[:-3]).replace(os.sep, '/') entries_text.append(this_entry) for entry_text in entries_text: fhindex += entry_text # clear at the end of the section fhindex += """.. raw:: html\n <div class="sphx-glr-clear"></div>\n\n""" return fhindex, costs
Example #10
Source File: gen_rst.py From sphinx-gallery with BSD 3-Clause "New" or "Revised" License | 4 votes |
def save_rst_example(example_rst, example_file, time_elapsed, memory_used, gallery_conf): """Saves the rst notebook to example_file including header & footer Parameters ---------- example_rst : str rst containing the executed file content example_file : str Filename with full path of python example file in documentation folder time_elapsed : float Time elapsed in seconds while executing file memory_used : float Additional memory used during the run. gallery_conf : dict Sphinx-Gallery configuration dictionary """ ref_fname = os.path.relpath(example_file, gallery_conf['src_dir']) ref_fname = ref_fname.replace(os.path.sep, "_") binder_conf = check_binder_conf(gallery_conf.get('binder')) binder_text = (" or to run this example in your browser via Binder" if len(binder_conf) else "") example_rst = (".. only:: html\n\n" " .. note::\n" " :class: sphx-glr-download-link-note\n\n" " Click :ref:`here <sphx_glr_download_{0}>` " " to download the full example code{1}\n" " .. rst-class:: sphx-glr-example-title\n\n" " .. _sphx_glr_{0}:\n\n" ).format(ref_fname, binder_text) + example_rst if time_elapsed >= gallery_conf["min_reported_time"]: time_m, time_s = divmod(time_elapsed, 60) example_rst += TIMING_CONTENT.format(time_m, time_s) if gallery_conf['show_memory']: example_rst += ("**Estimated memory usage:** {0: .0f} MB\n\n" .format(memory_used)) # Generate a binder URL if specified binder_badge_rst = '' if len(binder_conf) > 0: binder_badge_rst += gen_binder_rst(example_file, binder_conf, gallery_conf) fname = os.path.basename(example_file) example_rst += CODE_DOWNLOAD.format(fname, replace_py_ipynb(fname), binder_badge_rst, ref_fname) example_rst += SPHX_GLR_SIG write_file_new = re.sub(r'\.py$', '.rst.new', example_file) with codecs.open(write_file_new, 'w', encoding="utf-8") as f: f.write(example_rst) # in case it wasn't in our pattern, only replace the file if it's # still stale. _replace_md5(write_file_new)
Example #11
Source File: langhelpers.py From sqlalchemy with MIT License | 4 votes |
def monkeypatch_proxied_specials( into_cls, from_cls, skip=None, only=None, name="self.proxy", from_instance=None, ): """Automates delegation of __specials__ for a proxying type.""" if only: dunders = only else: if skip is None: skip = ( "__slots__", "__del__", "__getattribute__", "__metaclass__", "__getstate__", "__setstate__", ) dunders = [ m for m in dir(from_cls) if ( m.startswith("__") and m.endswith("__") and not hasattr(into_cls, m) and m not in skip ) ] for method in dunders: try: fn = getattr(from_cls, method) if not hasattr(fn, "__call__"): continue fn = getattr(fn, "im_func", fn) except AttributeError: continue try: spec = compat.inspect_getfullargspec(fn) fn_args = compat.inspect_formatargspec(spec[0]) d_args = compat.inspect_formatargspec(spec[0][1:]) except TypeError: fn_args = "(self, *args, **kw)" d_args = "(*args, **kw)" py = ( "def %(method)s%(fn_args)s: " "return %(name)s.%(method)s%(d_args)s" % locals() ) env = from_instance is not None and {name: from_instance} or {} compat.exec_(py, env) try: env[method].__defaults__ = fn.__defaults__ except AttributeError: pass setattr(into_cls, method, env[method])