back to SWE-Agent summary
SWE-Agent: marshmallow
Failed to run pytests for test tests
ImportError while loading conftest '/testbed/tests/conftest.py'.
tests/conftest.py:5: in <module>
from tests.base import Blog, User, UserSchema
tests/base.py:11: in <module>
from marshmallow import Schema, fields, missing, post_load, validate
src/marshmallow/__init__.py:17: in <module>
from marshmallow.schema import Schema, SchemaOpts
src/marshmallow/schema.py:15: in <module>
from marshmallow import fields as ma_fields
src/marshmallow/fields.py:18: in <module>
from marshmallow.utils import is_aware, is_collection, resolve_field_instance
E ImportError: cannot import name 'is_aware' from 'marshmallow.utils' (/testbed/src/marshmallow/utils.py)
Patch diff
diff --git a/src/marshmallow/schema.py b/src/marshmallow/schema.py
index 7b9efc5..39e31da 100644
--- a/src/marshmallow/schema.py
+++ b/src/marshmallow/schema.py
@@ -26,7 +26,11 @@ def _get_fields(attrs):
:param attrs: Mapping of class attributes
"""
- pass
+ return [
+ (field_name, field_obj)
+ for field_name, field_obj in attrs.items()
+ if isinstance(field_obj, ma_fields.Field)
+ ]
def _get_fields_by_mro(klass):
"""Collect fields from a class, following its method resolution order. The
@@ -35,7 +39,13 @@ def _get_fields_by_mro(klass):
:param type klass: Class whose fields to retrieve
"""
- pass
+ fields = []
+ for base in klass.__mro__[1:]: # skip the class itself
+ if hasattr(base, '_declared_fields'):
+ fields.extend(base._declared_fields.items())
+ else:
+ fields.extend(_get_fields(base.__dict__))
+ return fields
class SchemaMeta(ABCMeta):
"""Metaclass for the Schema class. Binds the declared fields to
@@ -77,7 +87,12 @@ class SchemaMeta(ABCMeta):
:param inherited_fields: Inherited fields.
:param dict_cls: dict-like class to use for dict output Default to ``dict``.
"""
- pass
+ declared_fields = dict_cls()
+ for field_name, field_obj in inherited_fields + cls_fields:
+ if field_name in declared_fields:
+ continue
+ declared_fields[field_name] = field_obj
+ return declared_fields
def __init__(cls, name, bases, attrs):
super().__init__(name, bases, attrs)
@@ -91,7 +106,13 @@ class SchemaMeta(ABCMeta):
By doing this after constructing the class, we let standard inheritance
do all the hard work.
"""
- pass
+ hooks = defaultdict(list)
+ for attr_name in dir(cls):
+ attr = getattr(cls, attr_name)
+ if hasattr(attr, '__marshmallow_hook__'):
+ hook = getattr(attr, '__marshmallow_hook__')
+ hooks[hook.tag].append(attr_name)
+ return hooks
class SchemaOpts:
"""class Meta options for the :class:`Schema`. Defines defaults."""
@@ -500,4 +521,4 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
specified in ``class Meta``.
"""
pass
-BaseSchema = Schema
\ No newline at end of file
+BaseSchema = Schema