Skip to content

Empty patternProperties fails to compile #201

@mikemoritz

Description

@mikemoritz
Python 3.13.3 (main, Apr 29 2025, 12:24:14) [GCC 13.3.0] on linux
>>> import fastjsonschema
>>> schema = {'type': 'object', 'patternProperties': {}}
>>> fastjsonschema.compile(schema)
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    fastjsonschema.compile(schema)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/home/redox/git/python-fastjsonschema/fastjsonschema/__init__.py", line 225, in compile
    exec(code_generator.func_code, global_state)
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 10
    return data
IndentationError: expected an indented block after 'for' statement on line 9

>>> print(fastjsonschema.compile_to_code(schema))
VERSION = "2.21.2"
from decimal import Decimal
from fastjsonschema import JsonSchemaValueException, JsonSchemaValuesException


NoneType = type(None)

def validate(data, custom_formats={}, name_prefix=None):
    if not isinstance(data, (dict)):
        raise JsonSchemaValueException("" + (name_prefix or "data") + " must be object", value=data, name="" + (name_prefix or "data") + "", definition={'type': 'object', 'patternProperties': {}}, rule='type')
    data_is_dict = isinstance(data, dict)
    if data_is_dict:
        data_keys = set(data.keys())
        for data_key, data_val in data.items():
    return data

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions