Skip to content

Fixes #126: generator objects leak on Python 3 #154

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

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 10 additions & 5 deletions jsonschema/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ def __init__(

@classmethod
def check_schema(cls, schema):
for error in cls(cls.META_SCHEMA).iter_errors(schema):
for error in list(cls(cls.META_SCHEMA).iter_errors(
schema, _first_only=True)):
raise SchemaError.create_from(error)

def iter_errors(self, instance, _schema=None):
def iter_errors(self, instance, _schema=None, _first_only=False):
if _schema is None:
_schema = self.schema

Expand Down Expand Up @@ -104,6 +105,9 @@ def iter_errors(self, instance, _schema=None):
error.schema_path.appendleft(k)
yield error

if _first_only:
return

def descend(self, instance, schema, path=None, schema_path=None):
for error in self.iter_errors(instance, schema):
if path is not None:
Expand All @@ -113,7 +117,8 @@ def descend(self, instance, schema, path=None, schema_path=None):
yield error

def validate(self, *args, **kwargs):
for error in self.iter_errors(*args, **kwargs):
kwargs['_first_only'] = True
for error in list(self.iter_errors(*args, **kwargs)):
raise error

def is_type(self, instance, type):
Expand All @@ -132,8 +137,8 @@ def is_type(self, instance, type):
return isinstance(instance, pytypes)

def is_valid(self, instance, _schema=None):
error = next(self.iter_errors(instance, _schema), None)
return error is None
errors = list(self.iter_errors(instance, _schema, _first_only=True))
return not len(errors)

if version is not None:
Validator = validates(version)(Validator)
Expand Down