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

[pre-commit.ci] pre-commit autoupdate #535

Merged
merged 2 commits into from
Nov 20, 2023
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions src/marshmallow_sqlalchemy/convert.py
Original file line number Diff line number Diff line change
@@ -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")


Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/marshmallow_sqlalchemy/fields.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
44 changes: 22 additions & 22 deletions tests/test_conversion.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand All @@ -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))
Expand All @@ -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(
Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down