Skip to content

Commit

Permalink
Merge pull request #739 from mmerickel/fix.view-config-depth
Browse files Browse the repository at this point in the history
_depth argument to view_config is now relative to view_config
  • Loading branch information
mcdonc committed Dec 7, 2012
2 parents 1608b26 + ed14191 commit 8623289
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
12 changes: 12 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
next release
============

Backwards Incompatibilities
---------------------------

- Modified the ``_depth`` argument to ``pyramid.view.view_config`` to accept
a value relative to the invocation of ``view_config`` itself. Thus, when it
was previously expecting a value of ``1`` or greater, to reflect that
the caller of ``view_config`` is 1 stack frame away from ``venusian.attach``,
this implementation detail is now hidden.

1.4b1 (2012-11-21)
==================

Expand Down
2 changes: 1 addition & 1 deletion pyramid/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ def foo(): pass
self.assertEqual(config.pkg, pyramid.tests)

def test_call_withdepth(self):
decorator = self._makeOne(_depth=2)
decorator = self._makeOne(_depth=1)
venusian = DummyVenusian()
decorator.venusian = venusian
def foo(): pass
Expand Down
18 changes: 10 additions & 8 deletions pyramid/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,16 @@ def my_view(context, request):
out, its default will be the equivalent ``add_view`` default.
An additional keyword argument named ``_depth`` is provided for people who
wish to reuse this class from another decorator. It will be passed in to
the :term:`venusian` ``attach`` function as the depth of the callstack when
Venusian checks if the decorator is being used in a class or module
context. It's not often used, but it can be useful in this circumstance.
See the ``attach`` function in Venusian for more information.
wish to reuse this class from another decorator. The default value is
``0`` and should be specified relative to the ``view_config`` invocation.
It will be passed in to the :term:`venusian` ``attach`` function as the
depth of the callstack when Venusian checks if the decorator is being used
in a class or module context. It's not often used, but it can be useful
in this circumstance. See the ``attach`` function in Venusian for more
information.
See :ref:`mapping_views_using_a_decorator_section` for details about
using :class:`view_config`.
using :class:`pyramid.view.view_config`.
"""
venusian = venusian # for testing injection
Expand All @@ -197,14 +199,14 @@ def __init__(self, **settings):

def __call__(self, wrapped):
settings = self.__dict__.copy()
depth = settings.pop('_depth', 1)
depth = settings.pop('_depth', 0)

def callback(context, name, ob):
config = context.config.with_package(info.module)
config.add_view(view=ob, **settings)

info = self.venusian.attach(wrapped, callback, category='pyramid',
depth=depth)
depth=depth + 1)

if info.scope == 'class':
# if the decorator was attached to a method in a class, or
Expand Down

0 comments on commit 8623289

Please sign in to comment.