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

Does pass testsFix issue https://github.com/apiguy/flask-classy/issues/22

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

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 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 ;)
I'me sure the less about git though...