• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

docs/src/dictionary/H21-May-2021-

pep562/H21-May-2021-257187

pep562.egg-info/H03-May-2022-137105

requirements/H03-May-2022-

tests/H21-May-2021-256182

CHANGES.mdH A D21-May-2021424 1710

LICENSE.mdH A D21-May-20211.1 KiB2217

MANIFEST.inH A D21-May-2021252 1211

PKG-INFOH A D21-May-20215.9 KiB137105

README.mdH A D21-May-20214 KiB11180

setup.cfgH A D21-May-202199 117

setup.pyH A D21-May-20212.1 KiB7559

tox.iniH A D21-May-2021604 3126

README.md

1[![Donate via PayPal][donate-image]][donate-link]
2[![Discord][discord-image]][discord-link]
3[![Build][github-ci-image]][github-ci-link]
4[![Coverage Status][codecov-image]][codecov-link]
5[![PyPI Version][pypi-image]][pypi-link]
6[![PyPI - Python Version][python-image]][pypi-link]
7![License][license-image-mit]
8
9# PEP 562
10
11## Overview
12
13A backport of PEP 562. Allows controlling a module's `__dir__` and `__getattr__`. Useful for deprecating attributes.
14Works for Python 2.7+. And while it works on Python 3.7, it is recommended to use the official Python 3.7 implementation
15where applicable.
16
17This module can be installed and used as a dependency, or if desired, it is easy to vendor as the license is quite
18permissible, and the code is contained in a single file.
19
20Once Python 3.6 is end of life, this module will be irrelevant and will no longer receive active support.
21
22## Install
23
24Installation is done with `pip`:
25
26```
27pip install pep562
28```
29
30## Vendoring
31
32Simply copy the file `pep562/__init__.py` to your project and rename to `pep562`.  Import and use as needed.
33
34## Usage
35
36Here is a simple example where we deprecate the attribute `version` for the more standardized `__version__`.
37
38```py
39from pep562 import pep562
40import warnings
41
42__version__ = (1, 0, 0)
43__all__ = ("__version__",)
44__deprecated__ = {
45    "version": ("__version__", __version__)
46}
47
48PY37 = sys.version_info >= (3, 7)
49
50
51def __getattr__(name):
52    """Get attribute."""
53
54    deprecated = __deprecated__.get(name)
55    if deprecated:
56        stacklevel = 3 if PY37 else 4
57        warnings.warn(
58            "'{}' is deprecated. Use '{}' instead.".format(name, deprecated[0]),
59            category=DeprecationWarning,
60            stacklevel=stacklevel
61        )
62        return deprecated[1]
63    raise AttributeError("module '{}' has no attribute '{}'".format(__name__, name))
64
65
66def __dir__():
67    """Module directory."""
68
69    return sorted(list(__all__) + list(__deprecated__.keys()))
70
71
72pep562(__name__)
73```
74
75## License
76
77MIT License
78
79Copyright (c) 2018 - 2021 Isaac Muse <isaacmuse@gmail.com>
80
81Permission is hereby granted, free of charge, to any person obtaining a copy
82of this software and associated documentation files (the "Software"), to deal
83in the Software without restriction, including without limitation the rights
84to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
85copies of the Software, and to permit persons to whom the Software is
86furnished to do so, subject to the following conditions:
87
88The above copyright notice and this permission notice shall be included in all
89copies or substantial portions of the Software.
90
91THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
92IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
93FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
94AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
95LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
96OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
97SOFTWARE.
98
99[github-ci-image]: https://github.com/facelessuser/pep562/workflows/build/badge.svg?branch=master&event=push
100[github-ci-link]: https://github.com/facelessuser/pep562/actions?query=workflow%3Abuild+branch%3Amaster
101[discord-image]: https://img.shields.io/discord/678289859768745989?logo=discord&logoColor=aaaaaa&color=mediumpurple&labelColor=333333
102[discord-link]:https://discord.gg/TWs8Tgr
103[codecov-image]: https://img.shields.io/codecov/c/github/facelessuser/pep562/master.svg?logo=codecov&logoColor=aaaaaa&labelColor=333333
104[codecov-link]: https://codecov.io/github/facelessuser/pep562
105[pypi-image]: https://img.shields.io/pypi/v/pep562.svg?logo=pypi&logoColor=aaaaaa&labelColor=333333
106[pypi-link]: https://pypi.python.org/pypi/pep562
107[python-image]: https://img.shields.io/pypi/pyversions/pep562?logo=python&logoColor=aaaaaa&labelColor=333333
108[license-image-mit]: https://img.shields.io/badge/license-MIT-blue.svg?labelColor=333333
109[donate-image]: https://img.shields.io/badge/Donate-PayPal-3fabd1?logo=paypal
110[donate-link]: https://www.paypal.me/facelessuser
111