hide_warnings
This is a python module that can hide any annoying warning messages from external C and C++ libraries in your python project. There is a decorator called hide_warnings in this module, you can decorate any of your functions with this decorator, then no warning messages from external C and C++ libraries (if invoked) in your function will be printed to cmd/terminal.
Installation
pip install hide_warnings
Usage
For example, here is a function that when you run it, a warning message from external C and C++ libraries will be forcibly printed to cmd/terminal, which is very annoying, and in python normally it is hard to prevent the warning messages from non-python libraries, especially when the functions that throw out these warning messages are from compiled C and C++ executables (which means you cannot modify the code inside it) and you pretty much need to modify the source code and rebuild yourself to prevent these warning messages, which takes some work, and what's even worse is that some closed source C and C++ projects does not give out source code for you to build.
What we want is to directly hide the warning messages we do not want to see from external C and C++ libraries in our python projects.
def func(a, b):
function_throw_external_warnings()
result = a + b
return result
>>> func(1, 2)
warning: This is some warnings from some external C and C++ functions
3
By decorating the function with hide_warnings, you can prevent these warning messages.
from hide_warnings import hide_warnings
@hide_warnings
def func(a, b):
function_throw_external_warnings()
result = a + b
return result
>>> func(1, 2)
3
Note that by default, all of the printed messages will be prevented inside the decorated function, including python's own print functions. If you still want to use python's print function to print some messages that is useful to you, you can set the keyword argument out to False for the decorator, which makes the decorated function could still use python's own print function.
from hide_warnings import hide_warnings
@hide_warnings(out=False)
def func(a, b):
function_throw_external_warnings()
print('this is a message')
result = a + b
return result
>>> func(1, 2)
this is a message
3
Metadata
Release files for hide-warnings 0.17
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hide_warnings-0.17.tar.gz | 12.0 kB | Without provenance | Details for hide_warnings-0.17.tar.gz |
Release files / hide_warnings-0.17.tar.gz
| Download URL | hide_warnings-0.17.tar.gz |
|---|---|
| Size | 12.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab8682f5c89b413a95ce79c357c03d6ebace0031875c723f8b07784781a6d16c
|
|
BLAKE2b-256 checksum How to use checksums |
326f6f1af28a72e53eb9ea5947b2ec1180c3bc91eca8439e931a7d247368f525
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.9
|
Security for hide-warnings 0.17
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.