Python warnings.html() Examples
The following are 30
code examples of warnings.html().
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: _utils.py From debtcollector with Apache License 2.0 | 6 votes |
def deprecation(message, stacklevel=None, category=None): """Warns about some type of deprecation that has been (or will be) made. This helper function makes it easier to interact with the warnings module by standardizing the arguments that the warning function receives so that it is easier to use. This should be used to emit warnings to users (users can easily turn these warnings off/on, see https://docs.python.org/2/library/warnings.html as they see fit so that the messages do not fill up the users logs with warnings that they do not wish to see in production) about functions, methods, attributes or other code that is deprecated and will be removed in a future release (this is done using these warnings to avoid breaking existing users of those functions, methods, code; which a library should avoid doing by always giving at *least* N + 1 release for users to address the deprecation warnings). """ if not _enabled: return if category is None: category = DeprecationWarning if stacklevel is None: warnings.warn(message, category=category) else: warnings.warn(message, category=category, stacklevel=stacklevel)
Example #2
Source File: util.py From qiskit-terra with Apache License 2.0 | 6 votes |
def _filter_deprecation_warnings(): """Apply filters to deprecation warnings. Force the `DeprecationWarning` warnings to be displayed for the qiskit module, overriding the system configuration as they are ignored by default [1] for end-users. Additionally, silence the `ChangedInMarshmallow3Warning` messages. TODO: on Python 3.7, this might not be needed due to PEP-0565 [2]. [1] https://docs.python.org/3/library/warnings.html#default-warning-filters [2] https://www.python.org/dev/peps/pep-0565/ """ deprecation_filter = ('always', None, DeprecationWarning, re.compile(r'^qiskit\.*', re.UNICODE), 0) # Instead of using warnings.simple_filter() directly, the internal # _add_filter() function is used for being able to match against the # module. try: warnings._add_filter(*deprecation_filter, append=False) except AttributeError: # ._add_filter is internal and not available in some Python versions. pass
Example #3
Source File: sqltypes.py From planespotter with MIT License | 6 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Integer: self.__class__, Interval: DateTime, Time: DateTime, }, operators.sub: { # date - integer = date Integer: self.__class__, # date - date = integer. Date: Integer, Interval: DateTime, # date - datetime = interval, # this one is not in the PG docs # but works DateTime: Interval, }, }
Example #4
Source File: sqltypes.py From planespotter with MIT License | 6 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Date: DateTime, Interval: self.__class__, DateTime: DateTime, Time: Time, }, operators.sub: { Interval: self.__class__ }, operators.mul: { Numeric: self.__class__ }, operators.truediv: { Numeric: self.__class__ }, operators.div: { Numeric: self.__class__ } }
Example #5
Source File: sqltypes.py From sqlalchemy with MIT License | 6 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Integer: self.__class__, Interval: DateTime, Time: DateTime, }, operators.sub: { # date - integer = date Integer: self.__class__, # date - date = integer. Date: Integer, Interval: DateTime, # date - datetime = interval, # this one is not in the PG docs # but works DateTime: Interval, }, }
Example #6
Source File: sqltypes.py From sqlalchemy with MIT License | 6 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Date: DateTime, Interval: self.__class__, DateTime: DateTime, Time: Time, }, operators.sub: {Interval: self.__class__}, operators.mul: {Numeric: self.__class__}, operators.truediv: {Numeric: self.__class__}, operators.div: {Numeric: self.__class__}, }
Example #7
Source File: sqltypes.py From jarvis with GNU General Public License v2.0 | 6 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Integer: self.__class__, Interval: DateTime, Time: DateTime, }, operators.sub: { # date - integer = date Integer: self.__class__, # date - date = integer. Date: Integer, Interval: DateTime, # date - datetime = interval, # this one is not in the PG docs # but works DateTime: Interval, }, }
Example #8
Source File: sqltypes.py From jarvis with GNU General Public License v2.0 | 6 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Date: DateTime, Interval: self.__class__, DateTime: DateTime, Time: Time, }, operators.sub: { Interval: self.__class__ }, operators.mul: { Numeric: self.__class__ }, operators.truediv: { Numeric: self.__class__ }, operators.div: { Numeric: self.__class__ } }
Example #9
Source File: warnings.py From python-netsurv with MIT License | 5 votes |
def pytest_configure(config): config.addinivalue_line( "markers", "filterwarnings(warning): add a warning filter to the given test. " "see https://docs.pytest.org/en/latest/warnings.html#pytest-mark-filterwarnings ", )
Example #10
Source File: recwarn.py From python-netsurv with MIT License | 5 votes |
def recwarn(): """Return a :class:`WarningsRecorder` instance that records all warnings emitted by test functions. See http://docs.python.org/library/warnings.html for information on warning categories. """ wrec = WarningsRecorder() with wrec: warnings.simplefilter("default") yield wrec
Example #11
Source File: warnings.py From python-netsurv with MIT License | 5 votes |
def pytest_configure(config): config.addinivalue_line( "markers", "filterwarnings(warning): add a warning filter to the given test. " "see https://docs.pytest.org/en/latest/warnings.html#pytest-mark-filterwarnings ", )
Example #12
Source File: recwarn.py From python-netsurv with MIT License | 5 votes |
def recwarn(): """Return a :class:`WarningsRecorder` instance that records all warnings emitted by test functions. See http://docs.python.org/library/warnings.html for information on warning categories. """ wrec = WarningsRecorder() with wrec: warnings.simplefilter("default") yield wrec
Example #13
Source File: test_utils.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_deprecated(): # Test whether the deprecated decorator issues appropriate warnings # Copied almost verbatim from https://docs.python.org/library/warnings.html # First a function... with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") @deprecated() def ham(): return "spam" spam = ham() assert_equal(spam, "spam") # function must remain usable assert_equal(len(w), 1) assert issubclass(w[0].category, DeprecationWarning) assert "deprecated" in str(w[0].message).lower() # ... then a class. with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") @deprecated("don't use this") class Ham: SPAM = 1 ham = Ham() assert hasattr(ham, "SPAM") assert_equal(len(w), 1) assert issubclass(w[0].category, DeprecationWarning) assert "deprecated" in str(w[0].message).lower()
Example #14
Source File: png.py From blenderseed with MIT License | 5 votes |
def group(s, n): # See http://www.python.org/doc/2.6/library/functions.html#zip return zip(*[iter(s)]*n)
Example #15
Source File: png.py From blenderseed with MIT License | 5 votes |
def interleave_planes(ipixels, apixels, ipsize, apsize): """ Interleave (colour) planes, e.g. RGB + A = RGBA. Return an array of pixels consisting of the `ipsize` elements of data from each pixel in `ipixels` followed by the `apsize` elements of data from each pixel in `apixels`. Conventionally `ipixels` and `apixels` are byte arrays so the sizes are bytes, but it actually works with any arrays of the same type. The returned array is the same type as the input arrays which should be the same type as each other. """ itotal = len(ipixels) atotal = len(apixels) newtotal = itotal + atotal newpsize = ipsize + apsize # Set up the output buffer # See http://www.python.org/doc/2.4.4/lib/module-array.html#l2h-1356 out = array(ipixels.typecode) # It's annoying that there is no cheap way to set the array size :-( out.extend(ipixels) out.extend(apixels) # Interleave in the pixel data for i in range(ipsize): out[i:newtotal:newpsize] = ipixels[i:itotal:ipsize] for i in range(apsize): out[i+ipsize:newtotal:newpsize] = apixels[i:atotal:apsize] return out
Example #16
Source File: png.py From blenderseed with MIT License | 5 votes |
def isinteger(x): try: return int(x) == x except (TypeError, ValueError): return False # === Legacy Version Support === # :pyver:old: PyPNG works on Python versions 2.3 and 2.2, but not # without some awkward problems. Really PyPNG works on Python 2.4 (and # above); it works on Pythons 2.3 and 2.2 by virtue of fixing up # problems here. It's a bit ugly (which is why it's hidden down here). # # Generally the strategy is one of pretending that we're running on # Python 2.4 (or above), and patching up the library support on earlier # versions so that it looks enough like Python 2.4. When it comes to # Python 2.2 there is one thing we cannot patch: extended slices # http://www.python.org/doc/2.3/whatsnew/section-slices.html. # Instead we simply declare that features that are implemented using # extended slices will not work on Python 2.2. # # In order to work on Python 2.3 we fix up a recurring annoyance involving # the array type. In Python 2.3 an array cannot be initialised with an # array, and it cannot be extended with a list (or other sequence). # Both of those are repeated issues in the code. Whilst I would not # normally tolerate this sort of behaviour, here we "shim" a replacement # for array into place (and hope no-one notices). You never read this. # # In an amusing case of warty hacks on top of warty hacks... the array # shimming we try and do only works on Python 2.3 and above (you can't # subclass array.array in Python 2.2). So to get it working on Python # 2.2 we go for something much simpler and (probably) way slower.
Example #17
Source File: png.py From iaf with MIT License | 5 votes |
def group(s, n): # See http://www.python.org/doc/2.6/library/functions.html#zip return list(zip(*[iter(s)]*n))
Example #18
Source File: png.py From iaf with MIT License | 5 votes |
def interleave_planes(ipixels, apixels, ipsize, apsize): """ Interleave (colour) planes, e.g. RGB + A = RGBA. Return an array of pixels consisting of the `ipsize` elements of data from each pixel in `ipixels` followed by the `apsize` elements of data from each pixel in `apixels`. Conventionally `ipixels` and `apixels` are byte arrays so the sizes are bytes, but it actually works with any arrays of the same type. The returned array is the same type as the input arrays which should be the same type as each other. """ itotal = len(ipixels) atotal = len(apixels) newtotal = itotal + atotal newpsize = ipsize + apsize # Set up the output buffer # See http://www.python.org/doc/2.4.4/lib/module-array.html#l2h-1356 out = array(ipixels.typecode) # It's annoying that there is no cheap way to set the array size :-( out.extend(ipixels) out.extend(apixels) # Interleave in the pixel data for i in range(ipsize): out[i:newtotal:newpsize] = ipixels[i:itotal:ipsize] for i in range(apsize): out[i+ipsize:newtotal:newpsize] = apixels[i:atotal:apsize] return out
Example #19
Source File: png.py From script.module.urlresolver with GNU General Public License v2.0 | 5 votes |
def group(s, n): """Repack iterator items into groups""" # See http://www.python.org/doc/2.6/library/functions.html#zip return list(zip(*[iter(s)] * n))
Example #20
Source File: png.py From script.module.urlresolver with GNU General Public License v2.0 | 5 votes |
def interleave_planes(ipixels, apixels, ipsize, apsize): """ Interleave (colour) planes, e.g. RGB + A = RGBA. Return an array of pixels consisting of the `ipsize` elements of data from each pixel in `ipixels` followed by the `apsize` elements of data from each pixel in `apixels`. Conventionally `ipixels` and `apixels` are byte arrays so the sizes are bytes, but it actually works with any arrays of the same type. The returned array is the same type as the input arrays which should be the same type as each other. """ itotal = len(ipixels) atotal = len(apixels) newtotal = itotal + atotal newpsize = ipsize + apsize # Set up the output buffer # See http://www.python.org/doc/2.4.4/lib/module-array.html#l2h-1356 out = array(ipixels.typecode) # It's annoying that there is no cheap way to set the array size :-( out.extend(ipixels) out.extend(apixels) # Interleave in the pixel data for i in range(ipsize): out[i:newtotal:newpsize] = ipixels[i:itotal:ipsize] for i in range(apsize): out[i + ipsize:newtotal:newpsize] = apixels[i:atotal:apsize] return out
Example #21
Source File: warnings.py From pytest with MIT License | 5 votes |
def pytest_configure(config: Config) -> None: config.addinivalue_line( "markers", "filterwarnings(warning): add a warning filter to the given test. " "see https://docs.pytest.org/en/latest/warnings.html#pytest-mark-filterwarnings ", )
Example #22
Source File: recwarn.py From pytest with MIT License | 5 votes |
def recwarn() -> Generator["WarningsRecorder", None, None]: """Return a :class:`WarningsRecorder` instance that records all warnings emitted by test functions. See http://docs.python.org/library/warnings.html for information on warning categories. """ wrec = WarningsRecorder() with wrec: warnings.simplefilter("default") yield wrec
Example #23
Source File: png.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 5 votes |
def group(s, n): # See http://www.python.org/doc/2.6/library/functions.html#zip return list(zip(*[iter(s)]*n))
Example #24
Source File: png.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 5 votes |
def interleave_planes(ipixels, apixels, ipsize, apsize): """ Interleave (colour) planes, e.g. RGB + A = RGBA. Return an array of pixels consisting of the `ipsize` elements of data from each pixel in `ipixels` followed by the `apsize` elements of data from each pixel in `apixels`. Conventionally `ipixels` and `apixels` are byte arrays so the sizes are bytes, but it actually works with any arrays of the same type. The returned array is the same type as the input arrays which should be the same type as each other. """ itotal = len(ipixels) atotal = len(apixels) newtotal = itotal + atotal newpsize = ipsize + apsize # Set up the output buffer # See http://www.python.org/doc/2.4.4/lib/module-array.html#l2h-1356 out = array(ipixels.typecode) # It's annoying that there is no cheap way to set the array size :-( out.extend(ipixels) out.extend(apixels) # Interleave in the pixel data for i in range(ipsize): out[i:newtotal:newpsize] = ipixels[i:itotal:ipsize] for i in range(apsize): out[i+ipsize:newtotal:newpsize] = apixels[i:atotal:apsize] return out
Example #25
Source File: png.py From GBVideoPlayer with MIT License | 5 votes |
def group(s, n): # See http://www.python.org/doc/2.6/library/functions.html#zip return zip(*[iter(s)]*n)
Example #26
Source File: png.py From GBVideoPlayer with MIT License | 5 votes |
def interleave_planes(ipixels, apixels, ipsize, apsize): """ Interleave (colour) planes, e.g. RGB + A = RGBA. Return an array of pixels consisting of the `ipsize` elements of data from each pixel in `ipixels` followed by the `apsize` elements of data from each pixel in `apixels`. Conventionally `ipixels` and `apixels` are byte arrays so the sizes are bytes, but it actually works with any arrays of the same type. The returned array is the same type as the input arrays which should be the same type as each other. """ itotal = len(ipixels) atotal = len(apixels) newtotal = itotal + atotal newpsize = ipsize + apsize # Set up the output buffer # See http://www.python.org/doc/2.4.4/lib/module-array.html#l2h-1356 out = array(ipixels.typecode) # It's annoying that there is no cheap way to set the array size :-( out.extend(ipixels) out.extend(apixels) # Interleave in the pixel data for i in range(ipsize): out[i:newtotal:newpsize] = ipixels[i:itotal:ipsize] for i in range(apsize): out[i+ipsize:newtotal:newpsize] = apixels[i:atotal:apsize] return out
Example #27
Source File: png.py From GBVideoPlayer with MIT License | 5 votes |
def isinteger(x): try: return int(x) == x except (TypeError, ValueError): return False # === Legacy Version Support === # :pyver:old: PyPNG works on Python versions 2.3 and 2.2, but not # without some awkward problems. Really PyPNG works on Python 2.4 (and # above); it works on Pythons 2.3 and 2.2 by virtue of fixing up # problems here. It's a bit ugly (which is why it's hidden down here). # # Generally the strategy is one of pretending that we're running on # Python 2.4 (or above), and patching up the library support on earlier # versions so that it looks enough like Python 2.4. When it comes to # Python 2.2 there is one thing we cannot patch: extended slices # http://www.python.org/doc/2.3/whatsnew/section-slices.html. # Instead we simply declare that features that are implemented using # extended slices will not work on Python 2.2. # # In order to work on Python 2.3 we fix up a recurring annoyance involving # the array type. In Python 2.3 an array cannot be initialised with an # array, and it cannot be extended with a list (or other sequence). # Both of those are repeated issues in the code. Whilst I would not # normally tolerate this sort of behaviour, here we "shim" a replacement # for array into place (and hope no-one notices). You never read this. # # In an amusing case of warty hacks on top of warty hacks... the array # shimming we try and do only works on Python 2.3 and above (you can't # subclass array.array in Python 2.2). So to get it working on Python # 2.2 we go for something much simpler and (probably) way slower.
Example #28
Source File: png.py From coastermelt with MIT License | 5 votes |
def group(s, n): # See # http://www.python.org/doc/2.6/library/functions.html#zip return zip(*[iter(s)]*n)
Example #29
Source File: png.py From coastermelt with MIT License | 5 votes |
def interleave_planes(ipixels, apixels, ipsize, apsize): """ Interleave (colour) planes, e.g. RGB + A = RGBA. Return an array of pixels consisting of the `ipsize` elements of data from each pixel in `ipixels` followed by the `apsize` elements of data from each pixel in `apixels`. Conventionally `ipixels` and `apixels` are byte arrays so the sizes are bytes, but it actually works with any arrays of the same type. The returned array is the same type as the input arrays which should be the same type as each other. """ itotal = len(ipixels) atotal = len(apixels) newtotal = itotal + atotal newpsize = ipsize + apsize # Set up the output buffer # See http://www.python.org/doc/2.4.4/lib/module-array.html#l2h-1356 out = array(ipixels.typecode) # It's annoying that there is no cheap way to set the array size :-( out.extend(ipixels) out.extend(apixels) # Interleave in the pixel data for i in range(ipsize): out[i:newtotal:newpsize] = ipixels[i:itotal:ipsize] for i in range(apsize): out[i+ipsize:newtotal:newpsize] = apixels[i:atotal:apsize] return out
Example #30
Source File: png.py From coastermelt with MIT License | 5 votes |
def mycallersname(): """Returns the name of the caller of the caller of this function (hence the name of the caller of the function in which "mycallersname()" textually appears). Returns None if this cannot be determined.""" # http://docs.python.org/library/inspect.html#the-interpreter-stack import inspect frame = inspect.currentframe() if not frame: return None frame_,filename_,lineno_,funname,linelist_,listi_ = ( inspect.getouterframes(frame)[2]) return funname