Skip to content

Commit 00c5b07

Browse files
committed
@ pallets-eco#25 | Special methods should work with Python 3.5 type hints
1 parent 22275b4 commit 00c5b07

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

flask_classful.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,11 @@ def get_interesting_members(base_class, cls):
357357
def get_true_argspec(method):
358358
"""Drills through layers of decorators attempting to locate the actual argspec for the method."""
359359

360-
argspec = inspect.getargspec(method)
360+
try:
361+
argspec = inspect.getargspec(method)
362+
except ValueError:
363+
argspec = inspect.getfullargspec(method)
364+
361365
args = argspec[0]
362366
if args and args[0] == 'self':
363367
return argspec

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[nosetests]
2+
where=test_classful
3+
py3where=.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def find_version(*file_paths):
3737
url='https://github.com/teracyhq/flask-classful',
3838
license='BSD',
3939
author='Freedom Dumlao & Teracy, Inc',
40-
author_email='teracyhq@teracy.com',
40+
author_email='hq@teracy.com',
4141
description='Class based views for Flask',
4242
long_description=__doc__,
4343
py_modules=['flask_classful'],

test_classful_py3/test_type_hints.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import sys
2+
3+
import json
4+
from flask import Flask
5+
from flask_classful import FlaskView, route
6+
from nose.tools import *
7+
8+
9+
# python3 only
10+
11+
class TypingView(FlaskView):
12+
13+
def index(self):
14+
return "Index"
15+
16+
@route('/<id>', methods=['POST'])
17+
def post(self, id: str) -> str:
18+
return "Post"
19+
20+
def patch(self, id: str) -> str:
21+
return "Patch"
22+
23+
24+
app = Flask('typing-app')
25+
TypingView.register(app)
26+
client = app.test_client()
27+
28+
29+
def test_index():
30+
resp = client.get('/typing/')
31+
eq_(b"Index", resp.data)
32+
33+
34+
def test_post():
35+
resp = client.post('/typing/123')
36+
eq_(b"Post", resp.data)
37+
38+
39+
def test_patch():
40+
resp = client.patch('/typing/123')
41+
eq_(b"Patch", resp.data)

0 commit comments

Comments
 (0)