From 30841b0d050cb3556b8a21af1dc418e63d36d925 Mon Sep 17 00:00:00 2001 From: Dillon Walls Date: Wed, 25 Jan 2023 15:38:19 +0000 Subject: [PATCH] Set all DeprecationWarning's stacklevel=2 to show caller --- ming/base.py | 6 ++++-- ming/mim.py | 10 +++++----- ming/odm/mapper.py | 2 +- ming/orm/__init__.py | 2 +- ming/orm/base.py | 2 +- ming/orm/declarative.py | 2 +- ming/orm/middleware.py | 2 +- ming/orm/ormsession.py | 2 +- ming/orm/property.py | 2 +- ming/utils.py | 2 +- 10 files changed, 17 insertions(+), 15 deletions(-) diff --git a/ming/base.py b/ming/base.py index 24d6a64..aa6229f 100644 --- a/ming/base.py +++ b/ming/base.py @@ -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) @@ -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): diff --git a/ming/mim.py b/ming/mim.py index 9bf4a07..b5a4bd1 100644 --- a/ming/mim.py +++ b/ming/mim.py @@ -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): @@ -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): @@ -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) @@ -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): @@ -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): diff --git a/ming/odm/mapper.py b/ming/odm/mapper.py index 921dee7..f92ef4d 100644 --- a/ming/odm/mapper.py +++ b/ming/odm/mapper.py @@ -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 diff --git a/ming/orm/__init__.py b/ming/orm/__init__.py index cb25e5b..f027b28 100644 --- a/ming/orm/__init__.py +++ b/ming/orm/__init__.py @@ -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 diff --git a/ming/orm/base.py b/ming/orm/base.py index c6057c0..f4d2613 100644 --- a/ming/orm/base.py +++ b/ming/orm/base.py @@ -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 * diff --git a/ming/orm/declarative.py b/ming/orm/declarative.py index af4e76e..ec66a98 100644 --- a/ming/orm/declarative.py +++ b/ming/orm/declarative.py @@ -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 * diff --git a/ming/orm/middleware.py b/ming/orm/middleware.py index 9a80959..3210653 100644 --- a/ming/orm/middleware.py +++ b/ming/orm/middleware.py @@ -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 * diff --git a/ming/orm/ormsession.py b/ming/orm/ormsession.py index 0f0477b..a0e7f63 100644 --- a/ming/orm/ormsession.py +++ b/ming/orm/ormsession.py @@ -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 diff --git a/ming/orm/property.py b/ming/orm/property.py index ecd690a..e470757 100644 --- a/ming/orm/property.py +++ b/ming/orm/property.py @@ -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 * diff --git a/ming/utils.py b/ming/utils.py index c1371fb..1be120f 100644 --- a/ming/utils.py +++ b/ming/utils.py @@ -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