From e51069db045ccc648435e3535723f3ac4a24b168 Mon Sep 17 00:00:00 2001 From: Theron Luhn Date: Mon, 1 Apr 2019 17:42:22 -0700 Subject: Improve debugging info from view_config decorator. Grab a frame when instanciating view_config, rather than pulling info from venusian's AttachInfo. See discussion at https://github.com/Pylons/pyramid/issues/3471 This fixes the build for Python 3.8. --- src/pyramid/view.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/pyramid/view.py b/src/pyramid/view.py index 944ad93ea..524e06fb2 100644 --- a/src/pyramid/view.py +++ b/src/pyramid/view.py @@ -1,5 +1,6 @@ import itertools import sys +import inspect import venusian @@ -216,6 +217,13 @@ class view_config(object): if settings.get('context') is None: settings['context'] = settings['for_'] self.__dict__.update(settings) + self._get_info() + + def _get_info(self): + frame = sys._getframe(2) + frameinfo = inspect.getframeinfo(frame) + sourceline = frameinfo[3][0].strip() + self._info = frameinfo[0], frameinfo[1], frameinfo[2], sourceline def __call__(self, wrapped): settings = self.__dict__.copy() @@ -237,14 +245,13 @@ class view_config(object): if settings.get('attr') is None: settings['attr'] = wrapped.__name__ - settings['_info'] = info.codeinfo # fbo "action_method" return wrapped bfg_view = view_config # bw compat (forever) -class view_defaults(view_config): +def view_defaults(**settings): """ A class :term:`decorator` which, when applied to a class, will provide defaults for all view configurations that use the class. This decorator accepts all the arguments accepted by @@ -253,10 +260,12 @@ class view_defaults(view_config): See :ref:`view_defaults` for more information. """ - def __call__(self, wrapped): - wrapped.__view_defaults__ = self.__dict__.copy() + def wrap(wrapped): + wrapped.__view_defaults__ = settings return wrapped + return wrap + class AppendSlashNotFoundViewFactory(object): """ There can only be one :term:`Not Found view` in any -- cgit v1.2.3