Python warnings.warn_explicit() Examples
The following are 30
code examples of warnings.warn_explicit().
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 stdm with GNU General Public License v2.0 | 6 votes |
def warn(msg, stacklevel=3): """Issue a warning. If msg is a string, :class:`.exc.SAWarning` is used as the category. .. note:: This function is swapped out when the test suite runs, with a compatible version that uses warnings.warn_explicit, so that the warnings registry can be controlled. """ if isinstance(msg, compat.string_types): warnings.warn(msg, exc.SAWarning, stacklevel=stacklevel) else: warnings.warn(msg, stacklevel=stacklevel)
Example #2
Source File: frontend.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
def handle_old_config(self, filename): warnings.warn_explicit(self.old_warning, ConfigDeprecationWarning, filename, 0) options = self.get_section('options') if not self.has_section('general'): self.add_section('general') for key, value in list(options.items()): if key in self.old_settings: section, setting = self.old_settings[key] if not self.has_section(section): self.add_section(section) else: section = 'general' setting = key if not self.has_option(section, setting): self.set(section, setting, value) self.remove_section('options')
Example #3
Source File: frontend.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
def handle_old_config(self, filename): warnings.warn_explicit(self.old_warning, ConfigDeprecationWarning, filename, 0) options = self.get_section('options') if not self.has_section('general'): self.add_section('general') for key, value in list(options.items()): if key in self.old_settings: section, setting = self.old_settings[key] if not self.has_section(section): self.add_section(section) else: section = 'general' setting = key if not self.has_option(section, setting): self.set(section, setting, value) self.remove_section('options')
Example #4
Source File: frontend.py From bash-lambda-layer with MIT License | 6 votes |
def handle_old_config(self, filename): warnings.warn_explicit(self.old_warning, ConfigDeprecationWarning, filename, 0) options = self.get_section('options') if not self.has_section('general'): self.add_section('general') for key, value in list(options.items()): if key in self.old_settings: section, setting = self.old_settings[key] if not self.has_section(section): self.add_section(section) else: section = 'general' setting = key if not self.has_option(section, setting): self.set(section, setting, value) self.remove_section('options')
Example #5
Source File: param_police.py From scanpy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def show_param_warnings(app, exception): import inspect for (fname, fun), params in param_warnings.items(): _, line = inspect.getsourcelines(fun) file_name = inspect.getsourcefile(fun) params_str = '\n'.join(f'\t{n}: {t}' for n, t in params) warnings.warn_explicit( f'\nParameters in `{fname}` have types in docstring.\n' f'Replace them with type annotations.\n{params_str}', UserWarning, file_name, line, ) if param_warnings: raise RuntimeError('Encountered text parameter type. Use annotations.')
Example #6
Source File: frontend.py From deepWordBug with Apache License 2.0 | 6 votes |
def handle_old_config(self, filename): warnings.warn_explicit(self.old_warning, ConfigDeprecationWarning, filename, 0) options = self.get_section('options') if not self.has_section('general'): self.add_section('general') for key, value in list(options.items()): if key in self.old_settings: section, setting = self.old_settings[key] if not self.has_section(section): self.add_section(section) else: section = 'general' setting = key if not self.has_option(section, setting): self.set(section, setting, value) self.remove_section('options')
Example #7
Source File: jelly.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def _unjelly_instance(self, rest): """ (internal) Unjelly an instance. Called to handle the deprecated I{instance} token. @param rest: The s-expression representing the instance. @return: The unjellied instance. """ warnings.warn_explicit( "Unjelly support for the instance atom is deprecated since " "Twisted 15.0.0. Upgrade peer for modern instance support.", category=DeprecationWarning, filename="", lineno=0) clz = self.unjelly(rest[0]) if not _PY3 and type(clz) is not _OldStyleClass: raise InsecureJelly("Legacy 'instance' found with new-style class") return self._genericUnjelly(clz, rest[1])
Example #8
Source File: frontend.py From blackmamba with MIT License | 6 votes |
def handle_old_config(self, filename): warnings.warn_explicit(self.old_warning, ConfigDeprecationWarning, filename, 0) options = self.get_section('options') if not self.has_section('general'): self.add_section('general') for key, value in list(options.items()): if key in self.old_settings: section, setting = self.old_settings[key] if not self.has_section(section): self.add_section(section) else: section = 'general' setting = key if not self.has_option(section, setting): self.set(section, setting, value) self.remove_section('options')
Example #9
Source File: frontend.py From aws-extender with MIT License | 6 votes |
def handle_old_config(self, filename): warnings.warn_explicit(self.old_warning, ConfigDeprecationWarning, filename, 0) options = self.get_section('options') if not self.has_section('general'): self.add_section('general') for key, value in options.items(): if key in self.old_settings: section, setting = self.old_settings[key] if not self.has_section(section): self.add_section(section) else: section = 'general' setting = key if not self.has_option(section, setting): self.set(section, setting, value) self.remove_section('options')
Example #10
Source File: deprecation.py From apm-agent-python with BSD 3-Clause "New" or "Revised" License | 6 votes |
def deprecated(alternative=None): """This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.""" def real_decorator(func): @functools.wraps(func) def new_func(*args, **kwargs): msg = "Call to deprecated function {0}.".format(func.__name__) if alternative: msg += " Use {0} instead".format(alternative) warnings.warn_explicit( msg, category=DeprecationWarning, filename=compat.get_function_code(func).co_filename, lineno=compat.get_function_code(func).co_firstlineno + 1, ) return func(*args, **kwargs) return new_func return real_decorator
Example #11
Source File: frontend.py From faces with GNU General Public License v2.0 | 6 votes |
def handle_old_config(self, filename): warnings.warn_explicit(self.old_warning, ConfigDeprecationWarning, filename, 0) options = self.get_section('options') if not self.has_section('general'): self.add_section('general') for key, value in options.items(): if key in self.old_settings: section, setting = self.old_settings[key] if not self.has_section(section): self.add_section(section) else: section = 'general' setting = key if not self.has_option(section, setting): self.set(section, setting, value) self.remove_section('options')
Example #12
Source File: frontend.py From faces with GNU General Public License v2.0 | 6 votes |
def handle_old_config(self, filename): warnings.warn_explicit(self.old_warning, ConfigDeprecationWarning, filename, 0) options = self.get_section('options') if not self.has_section('general'): self.add_section('general') for key, value in list(options.items()): if key in self.old_settings: section, setting = self.old_settings[key] if not self.has_section(section): self.add_section(section) else: section = 'general' setting = key if not self.has_option(section, setting): self.set(section, setting, value) self.remove_section('options')
Example #13
Source File: frontend.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 6 votes |
def handle_old_config(self, filename): warnings.warn_explicit(self.old_warning, ConfigDeprecationWarning, filename, 0) options = self.get_section('options') if not self.has_section('general'): self.add_section('general') for key, value in options.items(): if key in self.old_settings: section, setting = self.old_settings[key] if not self.has_section(section): self.add_section(section) else: section = 'general' setting = key if not self.has_option(section, setting): self.set(section, setting, value) self.remove_section('options')
Example #14
Source File: gccxmlparser.py From royal-chaos with MIT License | 6 votes |
def _get_calldef_exceptions(self, calldef): retval = [] for decl in calldef.exceptions: traits = ctypeparser.TypeTraits(normalize_name(decl.partial_decl_string)) if traits.type_is_reference: name = str(traits.target) else: name = str(traits.ctype) exc = self.type_registry.root_module.get(name, None) if isinstance(exc, CppException): retval.append(exc) else: warnings.warn_explicit("Thrown exception '%s' was not previously detected as an exception class." " PyBindGen bug?" % (normalize_name(decl.partial_decl_string)), WrapperWarning, calldef.location.file_name, calldef.location.line) return retval
Example #15
Source File: util.py From kcsrv with MIT License | 6 votes |
def deprecated(func): '''This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.''' @functools.wraps(func) def new_func(*args, **kwargs): warnings.warn_explicit( "Call to deprecated function {}.".format(func.__name__), category=DeprecationWarning, filename=func.func_code.co_filename, lineno=func.func_code.co_firstlineno + 1 ) return func(*args, **kwargs) return new_func
Example #16
Source File: misc.py From tellurium with Apache License 2.0 | 6 votes |
def deprecated(func): """This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used. """ @functools.wraps(func) def new_func(*args, **kwargs): warnings.warn_explicit( "Call to deprecated function {}.".format(func.__name__), category=DeprecationWarning, filename=func.func_code.co_filename, lineno=func.func_code.co_firstlineno + 1 ) return func(*args, **kwargs) return new_func # --------------------------------------------------------------------- # Running external tools # ---------------------------------------------------------------------
Example #17
Source File: jelly.py From learn_python3_spider with MIT License | 6 votes |
def _unjelly_instance(self, rest): """ (internal) Unjelly an instance. Called to handle the deprecated I{instance} token. @param rest: The s-expression representing the instance. @return: The unjellied instance. """ warnings.warn_explicit( "Unjelly support for the instance atom is deprecated since " "Twisted 15.0.0. Upgrade peer for modern instance support.", category=DeprecationWarning, filename="", lineno=0) clz = self.unjelly(rest[0]) if not _PY3 and type(clz) is not _OldStyleClass: raise InsecureJelly("Legacy 'instance' found with new-style class") return self._genericUnjelly(clz, rest[1])
Example #18
Source File: gccxmlparser.py From royal-chaos with MIT License | 6 votes |
def handle_error(self, wrapper, exception, traceback_): if hasattr(wrapper, "gccxml_definition"): definition = wrapper.gccxml_definition elif hasattr(wrapper, "main_wrapper"): try: definition = wrapper.main_wrapper.gccxml_definition except AttributeError: definition = None else: definition = None if definition is None: print("exception %r in wrapper %s" % (exception, wrapper), file=sys.stderr) else: warnings.warn_explicit("exception %r in wrapper for %s" % (exception, definition), WrapperWarning, definition.location.file_name, definition.location.line) return True
Example #19
Source File: __init__.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_once(self): with original_warnings.catch_warnings(record=True, module=self.module) as w: self.module.resetwarnings() self.module.filterwarnings("once", category=UserWarning) message = UserWarning("FilterTests.test_once") self.module.warn_explicit(message, UserWarning, "__init__.py", 42) self.assertEqual(w[-1].message, message) del w[:] self.module.warn_explicit(message, UserWarning, "__init__.py", 13) self.assertEqual(len(w), 0) self.module.warn_explicit(message, UserWarning, "test_warnings2.py", 42) self.assertEqual(len(w), 0)
Example #20
Source File: test_warnings.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_once(self): with original_warnings.catch_warnings(record=True, module=self.module) as w: self.module.resetwarnings() self.module.filterwarnings("once", category=UserWarning) message = UserWarning("FilterTests.test_once") self.module.warn_explicit(message, UserWarning, "test_warnings.py", 42) self.assertEqual(w[-1].message, message) del w[:] self.module.warn_explicit(message, UserWarning, "test_warnings.py", 13) self.assertEqual(len(w), 0) self.module.warn_explicit(message, UserWarning, "test_warnings2.py", 42) self.assertEqual(len(w), 0)
Example #21
Source File: deprecated.py From hgvs with Apache License 2.0 | 6 votes |
def __call__(self, func): msg = "Call to deprecated function {}".format(func.__name__) if self.use_instead: msg += '; use ' + self.use_instead + ' instead' def wrapper(*args, **kwargs): fingerprint = (func.__name__, func.__code__.co_filename, func.__code__.co_firstlineno) if fingerprint not in self.seen: warnings.warn_explicit( msg, category=DeprecationWarning, filename=func.__code__.co_filename, lineno=func.__code__.co_firstlineno + 1) self.seen.update([fingerprint]) return func(*args, **kwargs) wrapper.__doc__ = "Deprecated" if self.use_instead: wrapper.__doc__ += '; use ' + self.use_instead + ' instead' return wrapper
Example #22
Source File: __init__.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_once(self): with original_warnings.catch_warnings(record=True, module=self.module) as w: self.module.resetwarnings() self.module.filterwarnings("once", category=UserWarning) message = UserWarning("FilterTests.test_once") self.module.warn_explicit(message, UserWarning, "__init__.py", 42) self.assertEqual(w[-1].message, message) del w[:] self.module.warn_explicit(message, UserWarning, "__init__.py", 13) self.assertEqual(len(w), 0) self.module.warn_explicit(message, UserWarning, "test_warnings2.py", 42) self.assertEqual(len(w), 0)
Example #23
Source File: utils.py From TensorFlow_DCIGN with MIT License | 6 votes |
def deprecated(func): '''This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.''' @functools.wraps(func) def new_func(*args, **kwargs): warnings.warn_explicit( "Call to deprecated function {}.".format(func.__name__), category=DeprecationWarning, filename=func.func_code.co_filename, lineno=func.func_code.co_firstlineno + 1 ) return func(*args, **kwargs) return new_func
Example #24
Source File: decorators.py From arches with GNU Affero General Public License v3.0 | 6 votes |
def deprecated(func): """This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used. """ @functools.wraps(func) def new_func(*args, **kwargs): warnings.simplefilter("always", DeprecationWarning) # turn off filter warnings.warn_explicit( "Call to deprecated function {}.".format(func.__name__), category=DeprecationWarning, filename=func.__code__.co_filename, lineno=func.__code__.co_firstlineno + 1, ) warnings.simplefilter("default", DeprecationWarning) # reset filter logger.warn( "%s - DeprecationWarning: Call to deprecated function %s. %s:%s" % (datetime.datetime.now(), func.__name__, func.__code__.co_filename, func.__code__.co_firstlineno + 1) ) return func(*args, **kwargs) return new_func
Example #25
Source File: core.py From jams with ISC License | 6 votes |
def deprecated(version, version_removed): '''This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.''' def __wrapper(func, *args, **kwargs): '''Warn the user, and then proceed.''' code = six.get_function_code(func) warnings.warn_explicit( "{:s}.{:s}\n\tDeprecated as of JAMS version {:s}." "\n\tIt will be removed in JAMS version {:s}." .format(func.__module__, func.__name__, version, version_removed), category=DeprecationWarning, filename=code.co_filename, lineno=code.co_firstlineno + 1 ) return func(*args, **kwargs) return decorator(__wrapper)
Example #26
Source File: _sslverify.py From learn_python3_spider with MIT License | 5 votes |
def _selectVerifyImplementation(): """ Determine if C{service_identity} is installed. If so, use it. If not, use simplistic and incorrect checking as implemented in L{simpleVerifyHostname}. @return: 2-tuple of (C{verify_hostname}, C{VerificationError}) @rtype: L{tuple} """ whatsWrong = ( "Without the service_identity module, Twisted can perform only " "rudimentary TLS client hostname verification. Many valid " "certificate/hostname mappings may be rejected." ) try: from service_identity import VerificationError from service_identity.pyopenssl import ( verify_hostname, verify_ip_address ) return verify_hostname, verify_ip_address, VerificationError except ImportError as e: warnings.warn_explicit( "You do not have a working installation of the " "service_identity module: '" + str(e) + "'. " "Please install it from " "<https://pypi.python.org/pypi/service_identity> and make " "sure all of its dependencies are satisfied. " + whatsWrong, # Unfortunately the lineno is required. category=UserWarning, filename="", lineno=0) return simpleVerifyHostname, simpleVerifyIPAddress, SimpleVerificationError
Example #27
Source File: __init__.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_module_all_attribute(self): self.assertTrue(hasattr(self.module, '__all__')) target_api = ["warn", "warn_explicit", "showwarning", "formatwarning", "filterwarnings", "simplefilter", "resetwarnings", "catch_warnings"] self.assertSetEqual(set(self.module.__all__), set(target_api))
Example #28
Source File: test_warnings.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_mutate_filter_list(self): class X: def match(self, a): L[:] = [] L = [("default",X(),UserWarning,X(),0) for i in range(2)] with original_warnings.catch_warnings(record=True, module=self.module) as w: self.module.filters = L self.module.warn_explicit(UserWarning("b"), None, "f.py", 42) self.assertEqual(str(w[-1].message), "b")
Example #29
Source File: test_warnings.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_module_all_attribute(self): self.assertTrue(hasattr(self.module, '__all__')) target_api = ["warn", "warn_explicit", "showwarning", "formatwarning", "filterwarnings", "simplefilter", "resetwarnings", "catch_warnings"] self.assertSetEqual(set(self.module.__all__), set(target_api))
Example #30
Source File: decorators.py From nelpy with MIT License | 5 votes |
def deprecated(func): '''This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.''' @functools.wraps(func) def new_func(*args, **kwargs): warnings.warn_explicit( "Call to deprecated function {}.".format(func.__name__), category=DeprecationWarning, filename=func.__code__.co_filename, lineno=func.__code__.co_firstlineno + 1 ) return func(*args, **kwargs) new_func.__name__ = func.__name__ new_func.__doc__ = func.__doc__ new_func.__dict__.update(func.__dict__) return new_func # ## Usage examples ## # @deprecated # def my_func(): # pass # @other_decorators_must_be_upper # @deprecated # def my_func(): # pass