Name | displayhooks JSON |
Version |
0.0.2
JSON |
| download |
home_page | None |
Summary | Extend the capabilities of the standard displayhook in Python |
upload_time | 2024-08-27 10:51:13 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.7 |
license | None |
keywords |
repl
printing
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# displayhooks
[![Downloads](https://static.pepy.tech/badge/displayhooks/month)](https://pepy.tech/project/displayhooks)
[![Downloads](https://static.pepy.tech/badge/displayhooks)](https://pepy.tech/project/displayhooks)
[![codecov](https://codecov.io/gh/pomponchik/displayhooks/graph/badge.svg?token=UXXTj1AIcT)](https://codecov.io/gh/pomponchik/displayhooks)
[![Lines of code](https://sloc.xyz/github/pomponchik/displayhooks/?category=code)](https://github.com/boyter/scc/)
[![Hits-of-Code](https://hitsofcode.com/github/pomponchik/displayhooks?branch=main)](https://hitsofcode.com/github/pomponchik/displayhooks/view?branch=main)
[![Test-Package](https://github.com/pomponchik/displayhooks/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/metronomes/actions/workflows/tests_and_coverage.yml)
[![Python versions](https://img.shields.io/pypi/pyversions/displayhooks.svg)](https://pypi.python.org/pypi/displayhooks)
[![PyPI version](https://badge.fury.io/py/displayhooks.svg)](https://badge.fury.io/py/displayhooks)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
It's a micro library for manipulating [`sys.displayhook`](https://docs.python.org/3/library/sys.html#sys.displayhook).
When you need to change the standard behavior of `displayhook`, with this library you will do it:
- declaratively
- compactly
- beautifully
## Table of contents
- [**Quick start**](#quick-start)
- [**Change the displayed value**](#change-the-displayed-value)
- [**Prohibiting the display of certain types of values**](#prohibiting-the-display-of-certain-types-of-values)
- [**Automatic recovery of the default hook**](#automatic-recovery-of-the-default-hook)
## Quick start
Install it:
```bash
pip install displayhooks
```
And use:
```python
import sys
from displayhooks import not_display
not_display(int)
sys.displayhook('Most of the adventures recorded in this book really occurred; one or two were experiences of my own, the rest those of boys who were schoolmates of mine.')
#> 'Most of the adventures recorded in this book really occurred; one or two were experiences of my own, the rest those of boys who were schoolmates of mine.'
sys.displayhook(666)
# [nothing!]
```
## Change the displayed value
You can declaratively declare a converter function for the printed values. What it returns will be used to call the original `displayhook` function.
```python
import sys
from displayhooks import converted_displayhook
@converted_displayhook
def new_displayhook(value):
return value.lower()
sys.displayhook("What’s gone with that boy, I wonder? You TOM!")
#> 'what’s gone with that boy, i wonder? you tom!'
```
If your function returns `None`, nothing will be printed.
## Prohibiting the display of certain types of values
You can disable the display of certain data types, similar to how [`NoneType`](https://docs.python.org/3/library/types.html#types.NoneType) values are ignored by default.
You could already see a similar example above, let's look at it again:
```python
import sys
from types import FunctionType
from displayhooks import not_display
not_display(FunctionType)
sys.displayhook('Nothing! Look at your hands. And look at your mouth. What is that truck?')
#> 'Nothing! Look at your hands. And look at your mouth. What is that truck?'
sys.displayhook(lambda x: x)
# [nothing!]
```
In this example, you can see that we have disabled the display for functions, but all other data types are displayed unchanged.
## Automatic recovery of the default hook
You can limit the impact on [`sys.displayhook`](https://docs.python.org/3/library/sys.html#sys.displayhook) only to the code inside a function. If you hang the `autorestore_displayhook` decorator on it, after exiting the function, the displayhook that was installed before it was called will be automatically restored:
```python
import sys
from types import FunctionType
from displayhooks import not_display, autorestore_displayhook
@autorestore_displayhook
def do_something_dangerous():
not_display(FunctionType)
sys.displayhook(do_something_dangerous)
# [nothing!]
do_something_dangerous()
sys.displayhook(do_something_dangerous)
#> <function do_something_dangerous at 0x104c980e0>
```
Raw data
{
"_id": null,
"home_page": null,
"name": "displayhooks",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "REPL, printing",
"author": null,
"author_email": "Evgeniy Blinov <zheni-b@yandex.ru>",
"download_url": "https://files.pythonhosted.org/packages/6f/50/65a56b5cba83986a4bdf9b4a07ac26b3bac97f8349f0277cb2396c91774c/displayhooks-0.0.2.tar.gz",
"platform": null,
"description": "# displayhooks\n\n[![Downloads](https://static.pepy.tech/badge/displayhooks/month)](https://pepy.tech/project/displayhooks)\n[![Downloads](https://static.pepy.tech/badge/displayhooks)](https://pepy.tech/project/displayhooks)\n[![codecov](https://codecov.io/gh/pomponchik/displayhooks/graph/badge.svg?token=UXXTj1AIcT)](https://codecov.io/gh/pomponchik/displayhooks)\n[![Lines of code](https://sloc.xyz/github/pomponchik/displayhooks/?category=code)](https://github.com/boyter/scc/)\n[![Hits-of-Code](https://hitsofcode.com/github/pomponchik/displayhooks?branch=main)](https://hitsofcode.com/github/pomponchik/displayhooks/view?branch=main)\n[![Test-Package](https://github.com/pomponchik/displayhooks/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/metronomes/actions/workflows/tests_and_coverage.yml)\n[![Python versions](https://img.shields.io/pypi/pyversions/displayhooks.svg)](https://pypi.python.org/pypi/displayhooks)\n[![PyPI version](https://badge.fury.io/py/displayhooks.svg)](https://badge.fury.io/py/displayhooks)\n[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n\n\nIt's a micro library for manipulating [`sys.displayhook`](https://docs.python.org/3/library/sys.html#sys.displayhook).\n\nWhen you need to change the standard behavior of `displayhook`, with this library you will do it:\n\n- declaratively\n- compactly\n- beautifully\n\n\n## Table of contents\n\n- [**Quick start**](#quick-start)\n- [**Change the displayed value**](#change-the-displayed-value)\n- [**Prohibiting the display of certain types of values**](#prohibiting-the-display-of-certain-types-of-values)\n- [**Automatic recovery of the default hook**](#automatic-recovery-of-the-default-hook)\n\n\n## Quick start\n\nInstall it:\n\n```bash\npip install displayhooks\n```\n\nAnd use:\n\n```python\nimport sys\nfrom displayhooks import not_display\n\nnot_display(int)\n\nsys.displayhook('Most of the adventures recorded in this book really occurred; one or two were experiences of my own, the rest those of boys who were schoolmates of mine.')\n#> 'Most of the adventures recorded in this book really occurred; one or two were experiences of my own, the rest those of boys who were schoolmates of mine.'\nsys.displayhook(666)\n# [nothing!]\n```\n\n## Change the displayed value\n\nYou can declaratively declare a converter function for the printed values. What it returns will be used to call the original `displayhook` function.\n\n```python\nimport sys\nfrom displayhooks import converted_displayhook\n\n@converted_displayhook\ndef new_displayhook(value):\n return value.lower()\n\nsys.displayhook(\"What\u2019s gone with that boy, I wonder? You TOM!\")\n#> 'what\u2019s gone with that boy, i wonder? you tom!'\n```\n\nIf your function returns `None`, nothing will be printed.\n\n\n## Prohibiting the display of certain types of values\n\nYou can disable the display of certain data types, similar to how [`NoneType`](https://docs.python.org/3/library/types.html#types.NoneType) values are ignored by default.\n\nYou could already see a similar example above, let's look at it again:\n\n```python\nimport sys\nfrom types import FunctionType\nfrom displayhooks import not_display\n\nnot_display(FunctionType)\n\nsys.displayhook('Nothing! Look at your hands. And look at your mouth. What is that truck?')\n#> 'Nothing! Look at your hands. And look at your mouth. What is that truck?'\nsys.displayhook(lambda x: x)\n# [nothing!]\n```\n\nIn this example, you can see that we have disabled the display for functions, but all other data types are displayed unchanged.\n\n\n## Automatic recovery of the default hook\n\nYou can limit the impact on [`sys.displayhook`](https://docs.python.org/3/library/sys.html#sys.displayhook) only to the code inside a function. If you hang the `autorestore_displayhook` decorator on it, after exiting the function, the displayhook that was installed before it was called will be automatically restored:\n\n```python\nimport sys\nfrom types import FunctionType\nfrom displayhooks import not_display, autorestore_displayhook\n\n@autorestore_displayhook\ndef do_something_dangerous():\n not_display(FunctionType)\n sys.displayhook(do_something_dangerous)\n # [nothing!]\n\ndo_something_dangerous()\n\nsys.displayhook(do_something_dangerous)\n#> <function do_something_dangerous at 0x104c980e0>\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Extend the capabilities of the standard displayhook in Python",
"version": "0.0.2",
"project_urls": {
"Source": "https://github.com/pomponchik/displayhooks",
"Tracker": "https://github.com/pomponchik/displayhooks/issues"
},
"split_keywords": [
"repl",
" printing"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c6a66e8f289627943726a9b4a5c4d80864f74098a7367907804f3521658b1a5e",
"md5": "6c13b272192f6bd311c02267ea93a197",
"sha256": "7eb7b9b5dce2ff2db669cc31eb6526a13449e1d8d0ed054bfe4d9924cd130ebe"
},
"downloads": -1,
"filename": "displayhooks-0.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6c13b272192f6bd311c02267ea93a197",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 5356,
"upload_time": "2024-08-27T10:51:12",
"upload_time_iso_8601": "2024-08-27T10:51:12.100106Z",
"url": "https://files.pythonhosted.org/packages/c6/a6/6e8f289627943726a9b4a5c4d80864f74098a7367907804f3521658b1a5e/displayhooks-0.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6f5065a56b5cba83986a4bdf9b4a07ac26b3bac97f8349f0277cb2396c91774c",
"md5": "202af73c10394306e7d190c984377335",
"sha256": "bd72d833b2fd7eba5c5a5b05d486f8519f0e35ee573a759755f84697a81938d8"
},
"downloads": -1,
"filename": "displayhooks-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "202af73c10394306e7d190c984377335",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 5269,
"upload_time": "2024-08-27T10:51:13",
"upload_time_iso_8601": "2024-08-27T10:51:13.495825Z",
"url": "https://files.pythonhosted.org/packages/6f/50/65a56b5cba83986a4bdf9b4a07ac26b3bac97f8349f0277cb2396c91774c/displayhooks-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-27 10:51:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pomponchik",
"github_project": "displayhooks",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "displayhooks"
}