diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 930fc710..e9c909e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,10 +24,8 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', 'pypy-3.9'] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', 'pypy-3.9'] include: - - python-version: '3.6' - pytest-args: --ignore=tests/__generated__/test_recursive_postponned.py - python-version: '3.10' pytest-args: --cov=apischema --cov-branch --cov-report=xml --cov-report=html steps: diff --git a/apischema/json_schema/types.py b/apischema/json_schema/types.py index 659bbb86..daf4b9ee 100644 --- a/apischema/json_schema/types.py +++ b/apischema/json_schema/types.py @@ -34,6 +34,9 @@ class JsonType(str, Enum): def from_type(cls: Type) -> "JsonType": return TYPE_TO_JSON_TYPE[cls] + def __str__(self) -> str: + return self.value + class JsonTypes(Dict[type, JsonType]): def __missing__(self, key): diff --git a/apischema/typing.py b/apischema/typing.py index a89e7e8b..132163c4 100644 --- a/apischema/typing.py +++ b/apischema/typing.py @@ -94,7 +94,9 @@ def get_args(tp): except ImportError: pass -if sys.version_info >= (3, 7): +if sys.version_info >= (3, 11): + from typing import _collect_parameters as _collect_type_vars +elif sys.version_info >= (3, 7): from typing import _collect_type_vars # type: ignore else: from typing import _type_vars as _collect_type_vars @@ -274,7 +276,7 @@ def typing_origin(origin: Any) -> Any: def is_type(tp: Any) -> bool: """isinstance is not enough because in py39: isinstance(list[int], type) == True""" - return isinstance(tp, type) and not get_args(tp) + return isinstance(tp, type) and not get_args(tp) and tp is not Any def is_union(tp: Any) -> bool: diff --git a/examples/flattened.py b/examples/flattened.py index 2e673d39..f033df14 100644 --- a/examples/flattened.py +++ b/examples/flattened.py @@ -20,7 +20,7 @@ class RootJsonSchema: schema: str | UndefinedType = field(default=Undefined, metadata=alias("$schema")) defs: list[JsonSchema] = field(default_factory=list, metadata=alias("$defs")) # This field schema is flattened inside the owning one - json_schema: JsonSchema = field(default=JsonSchema(), metadata=flatten) + json_schema: JsonSchema = field(default_factory=JsonSchema, metadata=flatten) data = { diff --git a/examples/ordering.py b/examples/ordering.py index 6d61d085..2d666197 100644 --- a/examples/ordering.py +++ b/examples/ordering.py @@ -31,12 +31,12 @@ def age(self) -> int: user = User("Harry", "Potter", "London", date(1980, 7, 31)) -dump = """{ +dump = f"""{{ "trigram": "hpr", "firstname": "Harry", "lastname": "Potter", - "age": 41, + "age": {user.age}, "birthdate": "1980-07-31", "address": "London" -}""" +}}""" assert json.dumps(serialize(User, user), indent=4) == dump diff --git a/setup.cfg b/setup.cfg index d737efe3..5e3ecf3e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,6 +5,9 @@ ignore = E203, E302, E501, W503, E731, E741 [isort] profile = black +[tool:pytest] +asyncio_mode = auto + [coverage:report] ;fail_under = 100 precision = 2 @@ -17,4 +20,4 @@ exclude_lines = if TYPE_CHECKING stop_signature_abuse() if sys.version_info - def __getattr__(name): \ No newline at end of file + def __getattr__(name): diff --git a/tests/requirements.txt b/tests/requirements.txt index cf850048..2f3e6e22 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -6,7 +6,7 @@ docstring-parser==0.13 pydantic==1.9.0 pytest==7.0.1 pytest-cov==3.0.0 -pytest-asyncio==0.16.0 +pytest-asyncio==0.17.2 SQLAlchemy==1.4.32 typing-extensions==4.0.1 Cython==0.29.27