New team members regularly forget the parentheses when declaring a field. marshmallow notices and raises a TypeError meant to tell them which field it is and what to write instead, but the message comes out with its plac…
New team members regularly forget the parentheses when declaring a field. marshmallow notices and raises a TypeError meant to tell them which field it is and what to write instead, but the message comes out with its placeholders unfilled, so it helps nobody.
from marshmallow import Schema, fields
class UserSchema(Schema):
name = fields.String # no parentheses
age = fields.Integer()
UserSchema()
TypeError: Field for "name" must be declared as a Field instance, not a class. Did you mean "fields.String()"?
TypeError: Field for "{field_name}" must be declared as a Field instance, not a class. Did you mean "fields.{field_obj.__name__}()"?
fields.Str is reported as fields.String().Adapted from marshmallow-code/marshmallow (MIT).
Visible test command
pytest testsThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
field-class-error-message-placeholders
Changes under src/ are evaluated.