Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_depth argument to view_config is now relative to view_config #739

Merged
merged 1 commit into from
Dec 7, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
_depth argument to view_config is now relative to view_config
This hides an implementation detail that view_config is at least 1 level away
from user code.
  • Loading branch information
mmerickel committed Dec 6, 2012
commit ed14191bb41a891be258fc66e671bea8a25f7db1
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