Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use mypy.ignore_missing_imports instead of suppressing them everywhere manually #238

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ lint:
isort --check --diff --project=spectree ${SOURCE_FILES}
black --check --diff ${SOURCE_FILES}
flake8 ${SOURCE_FILES} --count --show-source --statistics
mypy --install-types --non-interactive --show-error-codes --warn-unused-ignores --disable-error-code attr-defined ${SOURCE_FILES}
mypy --install-types --non-interactive ${SOURCE_FILES}

.PHONY: test doc
2 changes: 1 addition & 1 deletion examples/falcon_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from random import random
from wsgiref import simple_server

import falcon # type: ignore
import falcon
from pydantic import BaseModel, Field

from spectree import Response, SpecTree, Tag
Expand Down
2 changes: 1 addition & 1 deletion examples/starlette_demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import uvicorn # type: ignore
import uvicorn
from pydantic import BaseModel, Field
from starlette.applications import Starlette
from starlette.endpoints import HTTPEndpoint
Expand Down
5 changes: 5 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[mypy]
ignore_missing_imports = true
show_error_codes = true
warn_unused_ignores = true
disable_error_code = attr-defined
4 changes: 2 additions & 2 deletions spectree/plugins/falcon_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class FalconPlugin(BasePlugin):
def __init__(self, spectree):
super().__init__(spectree)

from falcon import HTTP_400, HTTP_415, HTTPError # type: ignore
from falcon.routing.compiled import _FIELD_PATTERN # type: ignore
from falcon import HTTP_400, HTTP_415, HTTPError
from falcon.routing.compiled import _FIELD_PATTERN

# used to detect falcon 3.0 request media parse error
self.FALCON_HTTP_ERROR = HTTPError
Expand Down
3 changes: 2 additions & 1 deletion spectree/plugins/flask_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ def validate(
before(request, response, req_validation_error, None)
if req_validation_error:
after(request, response, req_validation_error, None)
abort(response) # type: ignore
assert response # make mypy happy
abort(response)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was weird. Removing type: ignore here passed when running it on my machine, but it was raising error when running here. When I put it back, it was complaining about unused ignore. So the way how to oveercome it was to make sure the response is not Optional.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes that happens even if the Python and mypy versions are the same. I'm not sure about the root cause.


result = func(*args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_plugin_falcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
try:
from falcon import App
except ImportError:
from falcon import API as App # type: ignore
from falcon import API as App

import pytest
from falcon import testing
Expand Down
4 changes: 2 additions & 2 deletions tests/test_plugin_falcon_asgi.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from random import randint

import pytest
from falcon import testing # type: ignore
from falcon import testing

from spectree import Response, SpecTree

from .common import JSON, Cookies, Headers, Query, Resp, StrDict, api_tag

pytest.importorskip("falcon", minversion="3.0.0", reason="Missing required Falcon 3.0")
from falcon.asgi import App # type: ignore # noqa: E402
from falcon.asgi import App # noqa: E402


def before_handler(req, resp, err, instance):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_spec.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
try:
from falcon import App as FalconApp
except ImportError:
from falcon import API as FalconApp # type: ignore
from falcon import API as FalconApp

import pytest
from flask import Flask
Expand Down