From: Heewa Barfchin Date: Mon, 3 Nov 2014 00:38:36 +0000 (-0500) Subject: Find real option definer. X-Git-Tag: v4.1.0b1~59^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1241%2Fhead;p=thirdparty%2Ftornado.git Find real option definer. When an option is defined through the module level "define" fn, not directly through the class method, we should look one frame up to find the real caller. --- diff --git a/tornado/options.py b/tornado/options.py index 5e23e2910..c855407c2 100644 --- a/tornado/options.py +++ b/tornado/options.py @@ -204,6 +204,13 @@ class OptionParser(object): (name, self._options[name].file_name)) frame = sys._getframe(0) options_file = frame.f_code.co_filename + + # Can be called directly, or through top level define() fn, in which + # case, step up above that frame to look for real caller. + if (frame.f_back.f_code.co_filename == options_file and + frame.f_back.f_code.co_name == 'define'): + frame = frame.f_back + file_name = frame.f_back.f_code.co_filename if file_name == options_file: file_name = ""