diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b379b8c3..ea5af624 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,16 +1,16 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.9.0 + rev: v3.15.0 hooks: - id: pyupgrade args: [--py37-plus] - repo: https://github.com/psf/black - rev: 23.7.0 + rev: 23.11.0 hooks: - id: black language_version: python3 - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 + rev: 6.1.0 hooks: - id: flake8 - additional_dependencies: [flake8-bugbear==23.1.14] + additional_dependencies: [flake8-bugbear==23.9.16] diff --git a/setup.py b/setup.py index b37c4bef..d0f818ec 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ "lint": [ "flake8==6.1.0", "flake8-bugbear==23.9.16", - "pre-commit==3.4.0", + "pre-commit==3.5.0", ], "docs": [ "sphinx==7.2.6", diff --git a/src/marshmallow_sqlalchemy/convert.py b/src/marshmallow_sqlalchemy/convert.py index fa97ebf9..6b8d6d45 100644 --- a/src/marshmallow_sqlalchemy/convert.py +++ b/src/marshmallow_sqlalchemy/convert.py @@ -1,19 +1,18 @@ -import inspect import functools +import inspect +import uuid import warnings -import uuid import marshmallow as ma -from marshmallow import validate, fields +import sqlalchemy as sa +from marshmallow import fields, validate from packaging.version import Version -from sqlalchemy.dialects import postgresql, mysql, mssql +from sqlalchemy.dialects import mssql, mysql, postgresql from sqlalchemy.orm import SynonymProperty -import sqlalchemy as sa from .exceptions import ModelConversionError from .fields import Related, RelatedList - _META_KWARGS_DEPRECATED = Version(ma.__version__) >= Version("3.10.0") @@ -302,6 +301,7 @@ def _get_field_kwargs_for_property(self, prop): 'Passing `info={"marshmallow": ...}` is deprecated. ' "Use `SQLAlchemySchema` and `auto_field` instead.", DeprecationWarning, + stacklevel=2, ) validate = overrides.pop("validate", []) kwargs["validate"] = self._merge_validators( diff --git a/src/marshmallow_sqlalchemy/fields.py b/src/marshmallow_sqlalchemy/fields.py index 2d48f4b6..ce2a6b64 100644 --- a/src/marshmallow_sqlalchemy/fields.py +++ b/src/marshmallow_sqlalchemy/fields.py @@ -1,7 +1,7 @@ import warnings + from marshmallow import fields from marshmallow.utils import is_iterable_but_not_string - from sqlalchemy import inspect from sqlalchemy.orm.exc import NoResultFound @@ -48,6 +48,7 @@ def __init__(self, columns=None, column=None, **kwargs): "`column` parameter is deprecated and will be removed in future releases. " "Use `columns` instead.", DeprecationWarning, + stacklevel=2, ) if columns is None: columns = column diff --git a/tests/test_conversion.py b/tests/test_conversion.py index 6059a6bc..0ad75144 100644 --- a/tests/test_conversion.py +++ b/tests/test_conversion.py @@ -1,20 +1,20 @@ -import uuid import datetime as dt import decimal +import uuid -import sqlalchemy as sa import pytest -from sqlalchemy.dialects import postgresql, mysql -from sqlalchemy.orm import column_property +import sqlalchemy as sa from marshmallow import Schema, fields, validate +from sqlalchemy.dialects import mysql, postgresql +from sqlalchemy.orm import column_property from marshmallow_sqlalchemy import ( - fields_for_model, + ModelConversionError, ModelConverter, - property2field, column2field, field_for, - ModelConversionError, + fields_for_model, + property2field, ) from marshmallow_sqlalchemy.fields import Related, RelatedList @@ -162,7 +162,7 @@ class MySchema(Schema): converter = ModelConverter(schema_cls=MySchema) prop = make_property(sa.DateTime()) field = converter.property2field(prop) - assert type(field) == MyDateTimeField + assert type(field) is MyDateTimeField @pytest.mark.parametrize( ("sa_type", "field_type"), @@ -193,27 +193,27 @@ class MySchema(Schema): def test_convert_types(self, converter, sa_type, field_type): prop = make_property(sa_type()) field = converter.property2field(prop) - assert type(field) == field_type + assert type(field) is field_type def test_convert_Numeric(self, converter): prop = make_property(sa.Numeric(scale=2)) field = converter.property2field(prop) - assert type(field) == fields.Decimal + assert type(field) is fields.Decimal assert field.places == decimal.Decimal((0, (1,), -2)) def test_convert_ARRAY_String(self, converter): prop = make_property(postgresql.ARRAY(sa.String())) field = converter.property2field(prop) - assert type(field) == fields.List + assert type(field) is fields.List inner_field = getattr(field, "inner", getattr(field, "container", None)) - assert type(inner_field) == fields.Str + assert type(inner_field) is fields.Str def test_convert_ARRAY_Integer(self, converter): prop = make_property(postgresql.ARRAY(sa.Integer)) field = converter.property2field(prop) - assert type(field) == fields.List + assert type(field) is fields.List inner_field = getattr(field, "inner", getattr(field, "container", None)) - assert type(inner_field) == fields.Int + assert type(inner_field) is fields.Int def test_convert_TSVECTOR(self, converter): prop = make_property(postgresql.TSVECTOR) @@ -261,10 +261,10 @@ def test_property2field(self): prop = make_property(sa.Integer()) field = property2field(prop, instance=True) - assert type(field) == fields.Int + assert type(field) is fields.Int field_cls = property2field(prop, instance=False) - assert field_cls == fields.Int + assert field_cls is fields.Int def test_can_pass_extra_kwargs(self): prop = make_property(sa.String()) @@ -277,10 +277,10 @@ def test_column2field(self): column = sa.Column(sa.String(255)) field = column2field(column, instance=True) - assert type(field) == fields.String + assert type(field) is fields.String field_cls = column2field(column, instance=False) - assert field_cls == fields.String + assert field_cls is fields.String def test_can_pass_extra_kwargs(self): column = sa.Column(sa.String(255)) @@ -305,13 +305,13 @@ class UUIDType(sa.types.TypeDecorator): class TestFieldFor: def test_field_for(self, models, session): field = field_for(models.Student, "full_name") - assert type(field) == fields.Str + assert type(field) is fields.Str field = field_for(models.Student, "current_school", session=session) - assert type(field) == Related + assert type(field) is Related field = field_for(models.Student, "full_name", field_class=fields.Date) - assert type(field) == fields.Date + assert type(field) is fields.Date def test_related_initialization_warning(self, models, session): with pytest.warns( @@ -350,7 +350,7 @@ class ModelWithArray(Base): bar = Column(ARRAY(String)) field = field_for(ModelWithArray, "bar", dump_only=True) - assert type(field) == fields.List + assert type(field) is fields.List assert field.dump_only is True diff --git a/tox.ini b/tox.ini index 7638ca5d..84ec2a65 100644 --- a/tox.ini +++ b/tox.ini @@ -16,7 +16,7 @@ deps = commands = pytest {posargs} [testenv:lint] -deps = pre-commit~=2.0 +deps = pre-commit~=3.5 skip_install = true commands = pre-commit run --all-files