Skip to content

Commit

Permalink
Rename "schema_cls" -> "schema_class"
Browse files Browse the repository at this point in the history
  • Loading branch information
sloria committed Mar 16, 2019
1 parent 458a3b7 commit 06e7b5c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/webargs/asyncparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def use_args(
# Optimization: If argmap is passed as a dictionary, we only need
# to generate a Schema once
if isinstance(argmap, Mapping):
argmap = core.dict2schema(argmap, self.schema_cls)()
argmap = core.dict2schema(argmap, self.schema_class)()

def decorator(func: typing.Callable) -> typing.Callable:
req_ = request_obj
Expand Down
14 changes: 7 additions & 7 deletions src/webargs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _callable_or_raise(obj):
return obj


def dict2schema(dct, schema_cls=ma.Schema):
def dict2schema(dct, schema_class=ma.Schema):
"""Generate a `marshmallow.Schema` class given a dictionary of
`Fields <marshmallow.fields.Field>`.
"""
Expand All @@ -64,7 +64,7 @@ class Meta(object):
register = False

attrs["Meta"] = Meta
return type(str(""), (schema_cls,), attrs)
return type(str(""), (schema_class,), attrs)


def is_multiple(field):
Expand Down Expand Up @@ -165,7 +165,7 @@ class Parser(object):
#: Default locations to check for data
DEFAULT_LOCATIONS = ("querystring", "form", "json")
#: The marshmallow Schema class to use when creating new schemas
DEFAULT_SCHEMA_CLS = ma.Schema
DEFAULT_SCHEMA_CLASS = ma.Schema
#: Default status code to return for validation errors
DEFAULT_VALIDATION_STATUS = DEFAULT_VALIDATION_STATUS
#: Default error message for validation errors
Expand All @@ -182,10 +182,10 @@ class Parser(object):
"files": "parse_files",
}

def __init__(self, locations=None, error_handler=None, schema_cls=None):
def __init__(self, locations=None, error_handler=None, schema_class=None):
self.locations = locations or self.DEFAULT_LOCATIONS
self.error_callback = _callable_or_raise(error_handler)
self.schema_cls = schema_cls or self.DEFAULT_SCHEMA_CLS
self.schema_class = schema_class or self.DEFAULT_SCHEMA_CLASS
#: A short-lived cache to store results from processing request bodies.
self._cache = {}

Expand Down Expand Up @@ -313,7 +313,7 @@ def _get_schema(self, argmap, req):
elif callable(argmap):
schema = argmap(req)
else:
schema = dict2schema(argmap, self.schema_cls)()
schema = dict2schema(argmap, self.schema_class)()
if MARSHMALLOW_VERSION_INFO[0] < 3 and not schema.strict:
warnings.warn(
"It is highly recommended that you set strict=True on your schema "
Expand Down Expand Up @@ -443,7 +443,7 @@ def greet(args):
# Optimization: If argmap is passed as a dictionary, we only need
# to generate a Schema once
if isinstance(argmap, Mapping):
argmap = dict2schema(argmap, self.schema_cls)()
argmap = dict2schema(argmap, self.schema_class)()

def decorator(func):
req_ = request_obj
Expand Down
2 changes: 1 addition & 1 deletion src/webargs/pyramidparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def use_args(
# Optimization: If argmap is passed as a dictionary, we only need
# to generate a Schema once
if isinstance(argmap, collections.Mapping):
argmap = core.dict2schema(argmap, self.schema_cls)()
argmap = core.dict2schema(argmap, self.schema_class)()

def decorator(func):
@functools.wraps(func)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ def test_parse_with_error_status_code_and_headers(web_request):


@mock.patch("webargs.core.Parser.parse_json")
def test_custom_schema_cls(parse_json, web_request):
def test_custom_schema_class(parse_json, web_request):
class CustomSchema(Schema):
@pre_load
def pre_load(self, data):
Expand All @@ -1064,21 +1064,21 @@ def pre_load(self, data):

parse_json.return_value = "hello"
argmap = {"value": fields.Str()}
p = Parser(schema_cls=CustomSchema)
p = Parser(schema_class=CustomSchema)
ret = p.parse(argmap, web_request)
assert ret == {"value": "hello world"}


@mock.patch("webargs.core.Parser.parse_json")
def test_custom_default_schema_cls(parse_json, web_request):
def test_custom_default_schema_class(parse_json, web_request):
class CustomSchema(Schema):
@pre_load
def pre_load(self, data):
data["value"] += " world"
return data

class CustomParser(Parser):
DEFAULT_SCHEMA_CLS = CustomSchema
DEFAULT_SCHEMA_CLASS = CustomSchema

parse_json.return_value = "hello"
argmap = {"value": fields.Str()}
Expand Down

0 comments on commit 06e7b5c

Please sign in to comment.