From cfa91b5caec80891c52cd6cc3d06adcbdd9fcc89 Mon Sep 17 00:00:00 2001 From: Keming Date: Sat, 1 Jul 2023 15:29:45 +0800 Subject: [PATCH] chore: fix pydantic to <2 (#318) Signed-off-by: Keming --- README.md | 2 +- pyproject.toml | 11 ++++++++--- setup.py | 2 +- spectree/_types.py | 6 +++--- spectree/plugins/__init__.py | 4 ++-- spectree/plugins/starlette_plugin.py | 6 ++++-- tests/test_config.py | 4 ++-- tests/test_plugin_quart.py | 3 +++ 8 files changed, 24 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b295e82f..1ad866bb 100644 --- a/README.md +++ b/README.md @@ -226,7 +226,7 @@ Code example: @api.validate( deprecated=True, ) -def depreated_endpoint(): +def deprecated_endpoint(): ... ``` diff --git a/pyproject.toml b/pyproject.toml index 934dbab9..b029667d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "spectree" -version = "1.1.3" +version = "1.1.4" dynamic = [] description = "generate OpenAPI document and validate request&response with Python annotations." readme = "README.md" @@ -34,9 +34,10 @@ dev = [ "mypy>=0.971", "pre-commit", "pytest~=7.1", + "syrupy>=4.0", ] email = [ - "pydantic[email]>=1.2", + "pydantic[email]>=1.2,<2", ] falcon = [ "falcon>=3.0.0", @@ -47,6 +48,10 @@ flask = [ starlette = [ "starlette[full]", ] +docs = [ + "Sphinx", + "furo", +] [project.urls] Homepage = "https://github.com/0b01001001/spectree" @@ -62,7 +67,7 @@ plugins = ["pydantic.mypy"] follow_imports = "silent" ignore_missing_imports = true show_error_codes = true -warn_unused_ignores = true +warn_unused_ignores = false warn_redundant_casts = true no_implicit_reexport = true disable_error_code = ["attr-defined"] diff --git a/setup.py b/setup.py index 34f9cc4d..bb137357 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ "pydantic>=1.2", ], extras_require={ - "email": ["pydantic[email]>=1.2"], + "email": ["pydantic[email]>=1.2,<2"], "flask": ["flask"], "quart": ["quart"], "falcon": ["falcon>=3.0.0"], diff --git a/spectree/_types.py b/spectree/_types.py index 5c36ee4d..79e93208 100644 --- a/spectree/_types.py +++ b/spectree/_types.py @@ -22,13 +22,13 @@ class MultiDict(Protocol): def get(self, key: str) -> Optional[str]: - ... + pass def getlist(self, key: str) -> List[str]: - ... + pass def __iter__(self) -> Iterator[str]: - ... + pass class FunctionDecorator(Protocol): diff --git a/spectree/plugins/__init__.py b/spectree/plugins/__init__.py index c5222258..0731b892 100644 --- a/spectree/plugins/__init__.py +++ b/spectree/plugins/__init__.py @@ -2,8 +2,6 @@ from .base import BasePlugin -__all__ = ["BasePlugin"] - Plugin = namedtuple("Plugin", ("name", "package", "class_name")) PLUGINS = { @@ -14,3 +12,5 @@ "falcon-asgi": Plugin(".falcon_plugin", __name__, "FalconAsgiPlugin"), "starlette": Plugin(".starlette_plugin", __name__, "StarlettePlugin"), } + +__all__ = ["BasePlugin", "PLUGINS", "Plugin"] diff --git a/spectree/plugins/starlette_plugin.py b/spectree/plugins/starlette_plugin.py index f0ef2226..5dabdc26 100644 --- a/spectree/plugins/starlette_plugin.py +++ b/spectree/plugins/starlette_plugin.py @@ -157,8 +157,10 @@ def parse_route(app, prefix=""): if isinstance(func, partial): try: func = func.__wrapped__ - except AttributeError: - pass + except AttributeError as err: + self.logger.warning( + "failed to get the wrapped func %s: %s", func, err + ) if inspect.isclass(func): for method in METHODS: diff --git a/tests/test_config.py b/tests/test_config.py index 17cfb4f8..c4716542 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -21,7 +21,7 @@ def test_config_license(): assert config.license.url == "https://opensource.org/licenses/MIT" with pytest.raises(ValidationError): - config = Configuration(license={"name": "MIT", "url": "url"}) + Configuration(license={"name": "MIT", "url": "url"}) def test_config_contact(): @@ -37,7 +37,7 @@ def test_config_contact(): assert config.contact.email == "hello@github.com" with pytest.raises(ValidationError): - config = Configuration(contact={"name": "John", "url": "url"}) + Configuration(contact={"name": "John", "url": "url"}) @pytest.mark.skipif(EmailFieldType == str, reason="email-validator is not installled") diff --git a/tests/test_plugin_quart.py b/tests/test_plugin_quart.py index f320c5cd..4b57b0cc 100644 --- a/tests/test_plugin_quart.py +++ b/tests/test_plugin_quart.py @@ -153,6 +153,7 @@ async def list_json(): # INFO: ensures that spec is calculated and cached _after_ registering # view functions for validations. This enables tests to access `api.spec` # without app_context. +# TODO: this is commented out because it requires async context # with app.app_context(): # api.spec api.register(app) @@ -262,6 +263,7 @@ async def oauth_two_ping(): return jsonify(msg="pong") +# TODO: this is commented out because it requires async context # with app_secure.app_context(): # api_secure.spec @@ -332,6 +334,7 @@ async def global_security_or(): return jsonify(msg="pong") +# TODO: this is commented out because it requires async context # with app_global_secure.app_context(): # api_global_secure.spec