Skip to content

Instantly share code, notes, and snippets.

@scardine
Created June 29, 2018 14:29
Show Gist options
  • Save scardine/509cd827cd6ec40c6c5f58c0de861555 to your computer and use it in GitHub Desktop.
Save scardine/509cd827cd6ec40c6c5f58c0de861555 to your computer and use it in GitHub Desktop.
Exemplo de Atributos Dinâmicos para Módulos no Python 3.7
# 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