Skip to content

Commit

Permalink
fix: Display correct location for deprecation warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
defnull committed Sep 5, 2024
1 parent 98bf0d7 commit 11f36c4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,13 @@ def update_wrapper(wrapper, wrapped, *a, **ka):
# And yes, I know PEP-8, but sometimes a lower-case classname makes more sense.


def depr(major, minor, cause, fix):
def depr(major, minor, cause, fix, stacklevel=3):
text = "Warning: Use of deprecated feature or API. (Deprecated in Bottle-%d.%d)\n"\
"Cause: %s\n"\
"Fix: %s\n" % (major, minor, cause, fix)
if DEBUG == 'strict':
raise DeprecationWarning(text)
warnings.warn(text, DeprecationWarning, stacklevel=3)
return DeprecationWarning(text)
warnings.warn(text, DeprecationWarning, stacklevel=stacklevel)


def makelist(data): # This is just too handy
Expand Down Expand Up @@ -339,7 +338,8 @@ def _itertokens(self, rule):
g = match.groups()
if g[2] is not None:
depr(0, 13, "Use of old route syntax.",
"Use <name> instead of :name in routes.")
"Use <name> instead of :name in routes.",
stacklevel=4)
if len(g[0]) % 2: # Escaped wildcard
prefix += match.group(0)[len(g[0]):]
offset = match.end()
Expand Down Expand Up @@ -416,7 +416,7 @@ def getargs(path):
if (flatpat, method) in self._groups:
if DEBUG:
msg = 'Route <%s %s> overwrites a previously defined route'
warnings.warn(msg % (method, rule), RuntimeWarning)
warnings.warn(msg % (method, rule), RuntimeWarning, stacklevel=3)
self.dyna_routes[method][
self._groups[flatpat, method]] = whole_rule
else:
Expand Down

0 comments on commit 11f36c4

Please sign in to comment.