Add location details to deprecation warning (#47155)

This commit is contained in:
Alan Tse 2021-03-16 13:16:07 -07:00 committed by GitHub
parent f3c74948c3
commit f86e7535e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 87 additions and 6 deletions

View file

@ -746,12 +746,21 @@ def deprecated(
def validator(config: Dict) -> Dict:
"""Check if key is in config and log warning."""
if key in config:
KeywordStyleAdapter(logging.getLogger(module_name)).warning(
warning,
key=key,
replacement_key=replacement_key,
)
try:
KeywordStyleAdapter(logging.getLogger(module_name)).warning(
warning.replace(
"'{key}' option",
f"'{key}' option near {config.__config_file__}:{config.__line__}", # type: ignore
),
key=key,
replacement_key=replacement_key,
)
except AttributeError:
KeywordStyleAdapter(logging.getLogger(module_name)).warning(
warning,
key=key,
replacement_key=replacement_key,
)
value = config[key]
if replacement_key:
config.pop(key)