Pylons/pyramid — pull request #1498 by sontek (2014-12-26 07:48:50+00:00)
Title: Add support for passing unbound class methods to `add_view`

This allows to do the following:

``` python
from pyramid.config import Configurator
from pyramid.response import Response
from waitress import serve

class View(object):
def __init__(self, request):
self.request = request

def hello_world(request):
return Response('Hello world!')

def create_app():
config = Configurator()
config.add_route('hello_world', '/')
config.add_view(View.hello_world, route_name='hello_world')

app = config.make_wsgi_app()
return app

if __name__ == '__main__':
app = create_app()
serve(app)

```

Before this PR you would get the exception:

```
Traceback (most recent call last):
File "app.py", line 21, in
app = create_app()
File "app.py", line 17, in create_app
app = config.make_wsgi_app()
File "/home/sontek/venvs/pyramid/src/pyramid/pyramid/config/__init__.py", line 956, in make_wsgi_app
self.commit()
File "/home/sontek/venvs/pyramid/src/pyramid/pyramid/config/__init__.py", line 625, in commit
self.action_state.execute_actions(introspector=self.introspector)
File "/home/sontek/venvs/pyramid/src/pyramid/pyramid/config/__init__.py", line 1084, in execute_actions
tb)
File "/home/sontek/venvs/pyramid/src/pyramid/pyramid/config/__init__.py", line 1076, in execute_actions
callable(*args, **kw)
File "/home/sontek/venvs/pyramid/src/pyramid/pyramid/config/views.py", line 1236, in register
derived_view = deriver(view)
File "/home/sontek/venvs/pyramid/src/pyramid/pyramid/config/views.py", line 159, in __call__
view)))))))))
File "/home/sontek/venvs/pyramid/src/pyramid/pyramid/config/views.py", line 103, in inner
wrapper_view = wrapper(self, view)
File "/home/sontek/venvs/pyramid/src/pyramid/pyramid/config/views.py", line 171, in mapped_view
mapped_view = mapper(**self.kw)(view)
File "/home/sontek/venvs/pyramid/src/pyramid/pyramid/config/views.py", line 424, in __call__
view = self.map_nonclass(view)
File "/home/sontek/venvs/pyramid/src/pyramid/pyramid/config/views.py", line 462, in map_nonclass
mapped_view.__text__ = object_description(view)
pyramid.exceptions.ConfigurationExecutionError: : 'instancemethod' object has no attribute '__text__'
in:
Line 15 of file app.py:
config.add_view(View.hello_world, route_name='hello_world')
```

The only thing I'm wondering is about the inconsistent way pyramid currently handles this. This would essentially remove the need for the `attr` argument.