Merge pull request #1265 from Elv13/improve_deprecation

Improve deprecation messages
This commit is contained in:
Emmanuel Lepage Vallée 2016-12-12 10:26:39 -05:00 committed by GitHub
commit f22c067efd
1 changed files with 8 additions and 3 deletions

View File

@ -37,7 +37,10 @@ util.shell = os.getenv("SHELL") or "/bin/sh"
local displayed_deprecations = {} local displayed_deprecations = {}
--- Display a deprecation notice, but only once per traceback. --- Display a deprecation notice, but only once per traceback.
-- @param[opt] see The message to a new method / function to use. -- @param[opt] see The message to a new method / function to use.
function util.deprecate(see) -- @tparam table args Extra arguments
-- @tparam boolean args.raw Print the message as-is without the automatic context
function util.deprecate(see, args)
args = args or {}
local tb = debug.traceback() local tb = debug.traceback()
if displayed_deprecations[tb] then if displayed_deprecations[tb] then
return return
@ -49,7 +52,9 @@ function util.deprecate(see)
local funcname = info.name or "?" local funcname = info.name or "?"
local msg = "awful: function " .. funcname .. " is deprecated" local msg = "awful: function " .. funcname .. " is deprecated"
if see then if see then
if string.sub(see, 1, 3) == 'Use' then if args.raw then
msg = see
elseif string.sub(see, 1, 3) == 'Use' then
msg = msg .. ". " .. see msg = msg .. ". " .. see
else else
msg = msg .. ", see " .. see msg = msg .. ", see " .. see
@ -80,7 +85,7 @@ function util.deprecate_class(fallback, old_name, new_name)
end end
local function newindex(_, k, v) local function newindex(_, k, v)
util.deprecate(message) util.deprecate(message, {raw = true})
fallback[k] = v fallback[k] = v
end end