Created
June 29, 2018 14:29
-
-
Save scardine/509cd827cd6ec40c6c5f58c0de861555 to your computer and use it in GitHub Desktop.
Exemplo de Atributos Dinâmicos para Módulos no Python 3.7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib.py | |
from warnings import warn | |
deprecated_names = ["funcao_antiga", ...] | |
def _funcao_antiga_obsoleta(arg, other): | |
... | |
def __getattr__(name): | |
if name in deprecated_names: | |
warn(f"{name} está obsoleta", DeprecationWarning) | |
return globals()[f"{name}_obsoleta"] | |
raise AttributeError(f"module {__name__} não possui um atributo {name}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment