Created
May 24, 2012 04:28
-
-
Save sharoonthomas/2779418 to your computer and use it in GitHub Desktop.
Example for stack level
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
test | |
Testing the warning stack level usage | |
:copyright: (c) 2012 by Openlabs Technologies & Consulting (P) Limited | |
:license: BSD, see LICENSE for more details. | |
""" | |
import warnings | |
#: Developer specific warning are usually ignored when run from itnerpreter | |
#: Force it to be displayed always | |
warnings.simplefilter('always', DeprecationWarning) | |
def level_1_warning(not_reqd_arg=None): | |
if not_reqd_arg is not None: | |
warnings.warn("A level 1 warning", DeprecationWarning, stacklevel=1) | |
return True | |
def level_2_warning(not_reqd_arg=None): | |
if not_reqd_arg is not None: | |
warnings.warn("A level 2 warning", DeprecationWarning, stacklevel=2) | |
return True | |
if __name__ == '__main__': | |
level_1_warning("Not None") | |
level_2_warning("Not None") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment