s-knibbs / dataclasses-jsonschema

JSON schema generation from dataclasses
MIT License
166 stars 38 forks source link

Add python 3.10 to tox and classifier #184

Closed ringohoffman closed 1 year ago

ringohoffman commented 2 years ago

For https://github.com/s-knibbs/dataclasses-jsonschema/issues/181:

Summary

New in version 3.10: dataclasses.field(..., kw_only=MISSING)

kw_only: If true, this field will be marked as keyword-only. This is used when the generated init() method’s parameters are computed.


dataclasses_jsonschema/apispec.py:38: error: Signature of "schema_helper" incompatible with supertype "BasePlugin"
dataclasses_jsonschema/apispec.py:38: note:      Superclass:
dataclasses_jsonschema/apispec.py:38: note:          def schema_helper(self, name: str, definition: Dict[Any, Any], **kwargs: Any) -> Optional[Dict[Any, Any]]
dataclasses_jsonschema/apispec.py:38: note:      Subclass:
dataclasses_jsonschema/apispec.py:38: note:          def [T <: JsonSchemaMixin] schema_helper(self, name: str, _: Any, *, schema: Union[Type[T], Dict[Any, Any], None] = ..., **kwargs: Any) -> Any

schema_helper(self, name: str, _: Any, *, schema: Union[Type[T], Dict[Any, Any], None] = None, **kwargs: Any)

schema_helper(self, name: str, definition: Any, **kwargs) + schema = kwargs.get("schema", None)

Testing

$ tox -e py310
GLOB sdist-make: /home/matthew/dataclasses-jsonschema/setup.py
py310 create: /home/matthew/dataclasses-jsonschema/.tox/py310
py310 installdeps: pytest, pytest-ordering, flake8, mypy, apispec[yaml], apispec_webframeworks, flask, types-python-dateutil
py310 inst: /home/matthew/dataclasses-jsonschema/.tox/.tmp/package/1/dataclasses-jsonschema-2.15.2.dev1+g58e3f8c.zip
py310 installed: apispec==5.2.1,apispec-webframeworks==0.5.2,attrs==21.4.0,click==8.1.3,dataclasses-jsonschema @ file:///home/matthew/dataclasses-jsonschema/.tox/.tmp/package/1/dataclasses-jsonschema-2.15.2.dev1%2Bg58e3f8c.zip,flake8==4.0.1,Flask==2.1.2,iniconfig==1.1.1,itsdangerous==2.1.2,Jinja2==3.1.2,jsonschema==4.5.1,MarkupSafe==2.1.1,mccabe==0.6.1,mypy==0.950,mypy-extensions==0.4.3,packaging==21.3,pluggy==1.0.0,py==1.11.0,pycodestyle==2.8.0,pyflakes==2.4.0,pyparsing==3.0.8,pyrsistent==0.18.1,pytest==7.1.2,pytest-ordering==0.6,python-dateutil==2.8.2,PyYAML==6.0,six==1.16.0,tomli==2.0.1,types-python-dateutil==2.8.15,typing_extensions==4.2.0,Werkzeug==2.1.2
py310 run-test-pre: PYTHONHASHSEED='1918695258'
py310 run-test: commands[0] | pytest tests
============================================================================================================ test session starts =============================================================================================================
platform linux -- Python 3.10.4, pytest-7.1.2, pluggy-1.0.0
cachedir: .tox/py310/.pytest_cache
rootdir: /home/matthew/dataclasses-jsonschema
plugins: ordering-0.6
collected 47 items                                                                                                                                                                                                                           

tests/test_core.py ............................................                                                                                                                                                                        [ 93%]
tests/test_peps.py ..                                                                                                                                                                                                                  [ 97%]
tests/test_apispec_plugin.py .                                                                                                                                                                                                         [100%]

============================================================================================================== warnings summary ==============================================================================================================
.tox/py310/lib/python3.10/site-packages/apispec/utils.py:104
  /home/matthew/dataclasses-jsonschema/.tox/py310/lib/python3.10/site-packages/apispec/utils.py:104: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    MIN_INCLUSIVE_VERSION = version.LooseVersion("2.0")

.tox/py310/lib/python3.10/site-packages/apispec/utils.py:105
  /home/matthew/dataclasses-jsonschema/.tox/py310/lib/python3.10/site-packages/apispec/utils.py:105: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    MAX_EXCLUSIVE_VERSION = version.LooseVersion("4.0")

.tox/py310/lib/python3.10/site-packages/setuptools/_distutils/version.py:351
.tox/py310/lib/python3.10/site-packages/setuptools/_distutils/version.py:351
  /home/matthew/dataclasses-jsonschema/.tox/py310/lib/python3.10/site-packages/setuptools/_distutils/version.py:351: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    other = LooseVersion(other)

.tox/py310/lib/python3.10/site-packages/apispec/utils.py:118
  /home/matthew/dataclasses-jsonschema/.tox/py310/lib/python3.10/site-packages/apispec/utils.py:118: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    super().__init__(openapi_version)

tests/test_apispec_plugin.py:144
  /home/matthew/dataclasses-jsonschema/tests/test_apispec_plugin.py:144: PytestUnknownMarkWarning: Unknown pytest.mark.last - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    @pytest.mark.last

tests/test_core.py::test_any_type_schema
  /home/matthew/dataclasses-jsonschema/dataclasses_jsonschema/__init__.py:732: UserWarning: Unable to create schema for 'Any'
    warnings.warn(f"Unable to create schema for '{field_type_name}'")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================================================================= 47 passed, 7 warnings in 0.22s =======================================================================================================
py310 run-test: commands[1] | flake8 dataclasses_jsonschema
py310 run-test: commands[2] | mypy dataclasses_jsonschema
Success: no issues found in 5 source files
__________________________________________________________________________________________________________________ summary ___________________________________________________________________________________________________________________
  py310: commands succeeded
  congratulations :)
elael commented 2 years ago

I believe you don't need to remove the arg schema: Union[Type[T], Dict[Any, Any], None] = None, just to change _: Any to definition: Any. I've faced the same issue with tox on my PR https://github.com/s-knibbs/dataclasses-jsonschema/pull/185