Commit 669187e5 authored by Lukáš Lalinský's avatar Lukáš Lalinský

Add mypy checks

parent 895067d4
Pipeline #20325 passed with stage
in 1 minute and 53 seconds
/.vagrant
/.mypy_cache
/e
/build
/acoustid.conf
......
......@@ -11,7 +11,7 @@ sync-reqs:
e/bin/pip-sync requirements.txt requirements_dev.txt
lint:
tox -e flake8
tox -e flake8,mypy
check:
tox
......
......@@ -2,6 +2,7 @@
# Distributed under the MIT license, see the LICENSE file for details.
import logging
from typing import Type
from acoustid.api import v2, serialize_response, errors
logger = logging.getLogger(__name__)
......@@ -18,7 +19,7 @@ class APIHandlerParams(v2.APIHandlerParams):
class APIHandler(v2.APIHandler):
params_class = None
params_class = None # type: Type[APIHandlerParams]
def _error(self, code, message, format=FORMAT, status=400):
assert format == FORMAT
......
......@@ -6,6 +6,7 @@ import logging
import json
import time
import operator
from typing import Type
from acoustid import const
from acoustid.const import MAX_REQUESTS_PER_SECOND
from acoustid.handler import Handler
......@@ -82,7 +83,7 @@ class APIHandlerParams(object):
class APIHandler(Handler):
params_class = None
params_class = None # type: Type[APIHandlerParams]
def __init__(self, connect=None):
self._connect = connect
......
from typing import Any
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from acoustid import tables
Base = declarative_base(metadata=tables.metadata)
Base = declarative_base(metadata=tables.metadata) # type: Any
class Account(Base):
......
......@@ -9,37 +9,36 @@ from werkzeug.exceptions import HTTPException
from werkzeug.routing import Map, Rule, Submount
from werkzeug.wrappers import Request
from werkzeug.contrib.fixers import ProxyFix
from acoustid import api
from acoustid.script import Script
import api.v1
import api.v2
import api.v2.misc
import api.v2.internal
import acoustid.api.v1
import acoustid.api.v2
import acoustid.api.v2.misc
import acoustid.api.v2.internal
api_url_rules = [
Rule('/_health', endpoint=api.HealthHandler),
Rule('/_health_ro', endpoint=api.ReadOnlyHealthHandler),
Rule('/_health_docker', endpoint=api.ReadOnlyHealthHandler),
Rule('/lookup', endpoint=api.v1.LookupHandler),
Rule('/submit', endpoint=api.v1.SubmitHandler),
Rule('/_health', endpoint=acoustid.api.HealthHandler),
Rule('/_health_ro', endpoint=acoustid.api.ReadOnlyHealthHandler),
Rule('/_health_docker', endpoint=acoustid.api.ReadOnlyHealthHandler),
Rule('/lookup', endpoint=acoustid.api.v1.LookupHandler),
Rule('/submit', endpoint=acoustid.api.v1.SubmitHandler),
Submount('/v2', [
Rule('/lookup', endpoint=api.v2.LookupHandler),
Rule('/submit', endpoint=api.v2.SubmitHandler),
Rule('/submission_status', endpoint=api.v2.SubmissionStatusHandler),
Rule('/fingerprint', endpoint=api.v2.misc.GetFingerprintHandler),
Rule('/track/list_by_mbid', endpoint=api.v2.misc.TrackListByMBIDHandler),
Rule('/track/list_by_puid', endpoint=api.v2.misc.TrackListByPUIDHandler),
Rule('/user/lookup', endpoint=api.v2.misc.UserLookupHandler),
Rule('/user/create_anonymous', endpoint=api.v2.misc.UserCreateAnonymousHandler),
Rule('/user/create_musicbrainz', endpoint=api.v2.misc.UserCreateMusicBrainzHandler),
Rule('/lookup', endpoint=acoustid.api.v2.LookupHandler),
Rule('/submit', endpoint=acoustid.api.v2.SubmitHandler),
Rule('/submission_status', endpoint=acoustid.api.v2.SubmissionStatusHandler),
Rule('/fingerprint', endpoint=acoustid.api.v2.misc.GetFingerprintHandler),
Rule('/track/list_by_mbid', endpoint=acoustid.api.v2.misc.TrackListByMBIDHandler),
Rule('/track/list_by_puid', endpoint=acoustid.api.v2.misc.TrackListByPUIDHandler),
Rule('/user/lookup', endpoint=acoustid.api.v2.misc.UserLookupHandler),
Rule('/user/create_anonymous', endpoint=acoustid.api.v2.misc.UserCreateAnonymousHandler),
Rule('/user/create_musicbrainz', endpoint=acoustid.api.v2.misc.UserCreateMusicBrainzHandler),
Submount('/internal', [
Rule('/update_lookup_stats', endpoint=api.v2.internal.UpdateLookupStatsHandler),
Rule('/update_user_agent_stats', endpoint=api.v2.internal.UpdateUserAgentStatsHandler),
Rule('/lookup_stats', endpoint=api.v2.internal.LookupStatsHandler),
Rule('/create_account', endpoint=api.v2.internal.CreateAccountHandler),
Rule('/create_application', endpoint=api.v2.internal.CreateApplicationHandler),
Rule('/update_application_status', endpoint=api.v2.internal.UpdateApplicationStatusHandler),
Rule('/update_lookup_stats', endpoint=acoustid.api.v2.internal.UpdateLookupStatsHandler),
Rule('/update_user_agent_stats', endpoint=acoustid.api.v2.internal.UpdateUserAgentStatsHandler),
Rule('/lookup_stats', endpoint=acoustid.api.v2.internal.LookupStatsHandler),
Rule('/create_account', endpoint=acoustid.api.v2.internal.CreateAccountHandler),
Rule('/create_application', endpoint=acoustid.api.v2.internal.CreateApplicationHandler),
Rule('/update_application_status', endpoint=acoustid.api.v2.internal.UpdateApplicationStatusHandler),
]),
]),
]
......
......@@ -140,4 +140,4 @@ if __name__ == "__main__":
'/api': make_api_application(app.acoustid_config_filename)[1],
})
run_simple(args.host, args.port, app, **run_args)
run_simple(args.host, args.port, app, **run_args) # type: ignore
# -*- coding: utf-8 -*-
import xml.sax
from xml.sax import ContentHandler
from xml.sax.handler import ErrorHandler
from xml.sax.handler import ContentHandler, ErrorHandler
class Rule(object):
......
......@@ -17,3 +17,4 @@ alembic>=0.8.4
uwsgi
schedule
sentry-sdk[flask]
typing
......@@ -37,6 +37,7 @@ schedule==0.6.0
sentry-sdk[flask]==0.7.14
six==1.12.0 # via cryptography, mbdata, pyopenssl, python-dateutil
sqlalchemy==1.3.3
typing==3.6.6
urllib3==1.24.2 # via requests, sentry-sdk
uwsgi==2.0.18
werkzeug==0.15.2
......@@ -82,7 +82,7 @@ def test_lookup_handler_params(conn):
@with_database
@unittest.skip
@unittest.skip("disabled")
def lookup_handler(conn):
values = {'client': 'app1key', 'length': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP}
builder = EnvironBuilder(method='POST', data=values)
......
......@@ -156,7 +156,7 @@ def test_apihandler_ws_error(conn):
@with_database
@unittest.skip
@unittest.skip("disabled")
def test_lookup_handler(conn):
values = {'format': 'json', 'client': 'app1key', 'duration': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP}
builder = EnvironBuilder(method='POST', data=values)
......
[tox]
envlist = py27, flake8
envlist = py27, mypy, flake8
skip_missing_interpreters = true
skipsdist = true
......@@ -11,11 +11,17 @@ commands = nosetests -v
setenv = PYTHONHASHSEED = 123
passenv = ACOUSTID_TEST_*
[testenv:mypy]
basepython = python3
skip_install = true
deps = mypy
commands = mypy --py2 --ignore-missing-imports acoustid/ tests/
[testenv:flake8]
basepython = python2
skip_install = true
deps = flake8
commands = python2 -m flake8 acoustid/ tests/
commands = flake8 acoustid/ tests/
[flake8]
ignore = E128
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment