Skip to content

Instantly share code, notes, and snippets.

@sharoonthomas
Created May 24, 2012 04:28
Show Gist options
  • Save sharoonthomas/2779418 to your computer and use it in GitHub Desktop.
Save sharoonthomas/2779418 to your computer and use it in GitHub Desktop.
Example for stack level
#!/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