Patchwork [1,of,8] util: add helper to define proxy functions to utils.*

login
register
mail settings
Submitter Yuya Nishihara
Date March 22, 2018, 3:01 p.m.
Message ID <bd6a3b24449e6e53bd9b.1521730912@mimosa>
Download mbox | patch
Permalink /patch/29780/
State Accepted
Headers show

Comments

Yuya Nishihara - March 22, 2018, 3:01 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1521720642 -32400
#      Thu Mar 22 21:10:42 2018 +0900
# Node ID bd6a3b24449e6e53bd9b4ed1be015d53b4db9cee
# Parent  1e30a26a65d077b3503cd746ee73fb99f3fb8033
util: add helper to define proxy functions to utils.*
Pulkit Goyal - March 22, 2018, 4:53 p.m.
On Thu, Mar 22, 2018 at 8:31 PM, Yuya Nishihara <yuya@tcha.org> wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1521720642 -32400
> #      Thu Mar 22 21:10:42 2018 +0900
> # Node ID bd6a3b24449e6e53bd9b4ed1be015d53b4db9cee
> # Parent  1e30a26a65d077b3503cd746ee73fb99f3fb8033
> util: add helper to define proxy functions to utils.*

Queued the series. Many thanks!
Boris FELD - March 23, 2018, 11:27 a.m.
Many, many thanks!


On 22/03/2018 17:53, Pulkit Goyal wrote:
> On Thu, Mar 22, 2018 at 8:31 PM, Yuya Nishihara <yuya@tcha.org> wrote:
>> # HG changeset patch
>> # User Yuya Nishihara <yuya@tcha.org>
>> # Date 1521720642 -32400
>> #      Thu Mar 22 21:10:42 2018 +0900
>> # Node ID bd6a3b24449e6e53bd9b4ed1be015d53b4db9cee
>> # Parent  1e30a26a65d077b3503cd746ee73fb99f3fb8033
>> util: add helper to define proxy functions to utils.*
> Queued the series. Many thanks!
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -4326,48 +4326,22 @@  def uvarintdecodestream(fh):
 # Deprecation warnings for util.py splitting
 ###
 
+def _deprecatedfunc(func, version):
+    def wrapped(*args, **kwargs):
+        fn = pycompat.sysbytes(func.__name__)
+        mn = pycompat.sysbytes(func.__module__)[len('mercurial.'):]
+        msg = "'util.%s' is deprecated, use '%s.%s'" % (fn, mn, fn)
+        nouideprecwarn(msg, version)
+        return func(*args, **kwargs)
+    wrapped.__name__ = func.__name__
+    return wrapped
+
 defaultdateformats = dateutil.defaultdateformats
-
 extendeddateformats = dateutil.extendeddateformats
-
-def makedate(*args, **kwargs):
-    msg = ("'util.makedate' is deprecated, "
-           "use 'utils.dateutil.makedate'")
-    nouideprecwarn(msg, "4.6")
-    return dateutil.makedate(*args, **kwargs)
-
-def datestr(*args, **kwargs):
-    msg = ("'util.datestr' is deprecated, "
-           "use 'utils.dateutil.datestr'")
-    nouideprecwarn(msg, "4.6")
-    return dateutil.datestr(*args, **kwargs)
-
-def shortdate(*args, **kwargs):
-    msg = ("'util.shortdate' is deprecated, "
-           "use 'utils.dateutil.shortdate'")
-    nouideprecwarn(msg, "4.6")
-    return dateutil.shortdate(*args, **kwargs)
-
-def parsetimezone(*args, **kwargs):
-    msg = ("'util.parsetimezone' is deprecated, "
-           "use 'utils.dateutil.parsetimezone'")
-    nouideprecwarn(msg, "4.6")
-    return dateutil.parsetimezone(*args, **kwargs)
-
-def strdate(*args, **kwargs):
-    msg = ("'util.strdate' is deprecated, "
-           "use 'utils.dateutil.strdate'")
-    nouideprecwarn(msg, "4.6")
-    return dateutil.strdate(*args, **kwargs)
-
-def parsedate(*args, **kwargs):
-    msg = ("'util.parsedate' is deprecated, "
-           "use 'utils.dateutil.parsedate'")
-    nouideprecwarn(msg, "4.6")
-    return dateutil.parsedate(*args, **kwargs)
-
-def matchdate(*args, **kwargs):
-    msg = ("'util.matchdate' is deprecated, "
-           "use 'utils.dateutil.matchdate'")
-    nouideprecwarn(msg, "4.6")
-    return dateutil.matchdate(*args, **kwargs)
+makedate = _deprecatedfunc(dateutil.makedate, '4.6')
+datestr = _deprecatedfunc(dateutil.datestr, '4.6')
+shortdate = _deprecatedfunc(dateutil.shortdate, '4.6')
+parsetimezone = _deprecatedfunc(dateutil.parsetimezone, '4.6')
+strdate = _deprecatedfunc(dateutil.strdate, '4.6')
+parsedate = _deprecatedfunc(dateutil.parsedate, '4.6')
+matchdate = _deprecatedfunc(dateutil.matchdate, '4.6')