apiguy/flask-classy — pull request #31 by ivan-kleshnin (2013-06-11 16:05:58+00:00)
Title: Fix issue #22 (rule lookup does not count inheritance)

The issue is with cache strictly bound to the class object.
Rule lookup doesn't count inheritance for now.

Then, if you have

```python
class BaseView(FlaskView):
@route('/delete/')
def delete(self, id=None):
pass

class PostsView(BaseView):
@route('test') # any route to provide new cache obj instance
def test(self): # and break behavior
pass
```

It generates

```python
Map(...
' (OPTIONS, DELETE) ...>,
)
```

While it should generate

```python
Map(...
' (HEAD, OPTIONS, GET) ...>
)
```

Diff looks a bit scary but basically i added just a 3 lines to deal with inheritance.
This fix passes all tests.

I fixed this fragment
```python
if hasattr(_cls, "_rule_cache") and name in _cls._rule_cache:
for idx, cached_rule in enumerate(_cls._rule_cache[name]):
...
elif name in special_methods:
...
````

by wrapping in `.mro()` lookup loop:

```python
for _cls in cls.mro()[:-1]: # -1 to skip `object` lookup
if hasattr(_cls, "_rule_cache") and name in _cls._rule_cache:
for idx, cached_rule in enumerate(_cls._rule_cache[name]):
...
break
else: # no break
if name in special_methods: # elif -> if
...

```

I'm not 100% sure about solution. Flask-Classy is kinda tricky ;)