Skip to content

Commit

Permalink
Set all DeprecationWarning's stacklevel=2 to show caller
Browse files Browse the repository at this point in the history
  • Loading branch information
dill0wn authored and brondsem committed Feb 6, 2023
1 parent 637a033 commit 30841b0
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 15 deletions.
6 changes: 4 additions & 2 deletions ming/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def from_bson(cls, bson):
def make_safe(self):
warnings.warn("make_safe is now deprecated. "
"If your code relies on make_safe for validation, "
"you should consider adding your own layer of validation", DeprecationWarning)
"you should consider adding your own layer of validation",
DeprecationWarning, stacklevel=2)
safe_self = _safe_bson(self)
self.update(safe_self)

Expand Down Expand Up @@ -141,7 +142,8 @@ def _safe_bson(obj, _no_warning=False):
if not _no_warning:
warnings.warn("_safe_bson is now deprecated. "
"If your code relies on _safe_bson for validation, "
"you should consider adding your own layer of validation", DeprecationWarning)
"you should consider adding your own layer of validation",
DeprecationWarning, stacklevel=2)
if isinstance(obj, list):
return [ _safe_bson(o, True) for o in obj ]
elif isinstance(obj, dict):
Expand Down
10 changes: 5 additions & 5 deletions ming/mim.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def __find_and_modify(self, query=None, update=None, fields=None,
def find_and_modify(self, query=None, update=None, fields=None,
upsert=False, remove=False, **kwargs):
warnings.warn('find_and_modify is now deprecated, please use find_one_and_delete, '
'find_one_and_replace, find_one_and_update)', DeprecationWarning)
'find_one_and_replace, find_one_and_update)', DeprecationWarning, stacklevel=2)
return self.__find_and_modify(query, update, fields, upsert, remove, **kwargs)

def find_one_and_delete(self, filter, projection=None, sort=None, **kwargs):
Expand Down Expand Up @@ -455,7 +455,7 @@ def __insert(self, doc_or_docs, manipulate=True, **kwargs):
return result

def insert(self, doc_or_docs, manipulate=True, **kwargs):
warnings.warn('insert is now deprecated, please use insert_one or insert_many', DeprecationWarning)
warnings.warn('insert is now deprecated, please use insert_one or insert_many', DeprecationWarning, stacklevel=2)
return self.__insert(doc_or_docs, manipulate, **kwargs)

def insert_one(self, document, session=None):
Expand All @@ -469,7 +469,7 @@ def insert_many(self, documents, ordered=True, session=None):
return InsertManyResult(result, True)

def save(self, doc, **kwargs):
warnings.warn('save is now deprecated, please use insert_one or replace_one', DeprecationWarning)
warnings.warn('save is now deprecated, please use insert_one or replace_one', DeprecationWarning, stacklevel=2)
_id = doc.get('_id', ())
if _id == ():
return self.__insert(doc)
Expand Down Expand Up @@ -517,7 +517,7 @@ def __update(self, spec, updates, upsert=False, multi=False):
return result

def update(self, spec, updates, upsert=False, multi=False):
warnings.warn('update is now deprecated, please use update_many or update_one', DeprecationWarning)
warnings.warn('update is now deprecated, please use update_many or update_one', DeprecationWarning, stacklevel=2)
return self.__update(spec, updates, upsert, multi)

def update_many(self, filter, update, upsert=False):
Expand All @@ -543,7 +543,7 @@ def __remove(self, spec=None, **kwargs):
return result

def remove(self, spec=None, **kwargs):
warnings.warn('remove is now deprecated, please use delete_many or delete_one', DeprecationWarning)
warnings.warn('remove is now deprecated, please use delete_many or delete_one', DeprecationWarning, stacklevel=2)
self.__remove(spec, **kwargs)

def delete_one(self, filter, session=None):
Expand Down
2 changes: 1 addition & 1 deletion ming/odm/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _from_doc(self, doc, options, validate=True):
"no schema. While this will work, please note that it's not "
"too useful, since no schema means that there are no fields "
"mapped from the database document onto the object.",
UserWarning)
UserWarning, stacklevel=2)
st.document = copy(doc)
st.status = st.new
return obj
Expand Down
2 changes: 1 addition & 1 deletion ming/orm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import warnings
warnings.warn(
'ming.orm is deprecated. Please use ming.odm instead',
DeprecationWarning)
DeprecationWarning, stacklevel=2)
from ming.odm import *

ORMSession=ODMSession
Expand Down
2 changes: 1 addition & 1 deletion ming/orm/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import warnings
warnings.warn(
'ming.orm.base is deprecated. Please use ming.odm.base instead',
DeprecationWarning)
DeprecationWarning, stacklevel=2)
from ming.odm.base import *
2 changes: 1 addition & 1 deletion ming/orm/declarative.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import warnings
warnings.warn(
'ming.orm.declarative is deprecated. Please use ming.odm.declarative instead',
DeprecationWarning)
DeprecationWarning, stacklevel=2)
from ming.odm.declarative import *
2 changes: 1 addition & 1 deletion ming/orm/middleware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import warnings
warnings.warn(
'ming.orm.middleware is deprecated. Please use ming.odm.middleware instead',
DeprecationWarning)
DeprecationWarning, stacklevel=2)
from ming.odm.middleware import *
2 changes: 1 addition & 1 deletion ming/orm/ormsession.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import warnings
warnings.warn(
'ming.orm.ormsession is deprecated. Use ming.odm.odmsession instead',
DeprecationWarning)
DeprecationWarning, stacklevel=2)
from ming.odm.odmsession import *

ORMSession = ODMSession
Expand Down
2 changes: 1 addition & 1 deletion ming/orm/property.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import warnings
warnings.warn(
'ming.orm.property is deprecated. Please use ming.odm.property instead',
DeprecationWarning)
DeprecationWarning, stacklevel=2)
from ming.odm.property import *
2 changes: 1 addition & 1 deletion ming/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ def _fixup(i):

def fix_write_concern(kwargs):
if 'safe' in kwargs:
warnings.warn('safe option is now deprecated', DeprecationWarning)
warnings.warn('safe option is now deprecated', DeprecationWarning, stacklevel=2)
kwargs['w'] = int(kwargs.pop('safe'))
return kwargs

0 comments on commit 30841b0

Please sign in to comment.