Skip to content

Pure array object can't be validated, throws TypeError: unhashable type: 'list' exception #870

@leonardopsantos

Description

@leonardopsantos

Hi there! I'm trying to validate a JSON schema that represents a tensor shape. I modelled it as a list of four numbers. I want this schema separate because other schemas will use and and I don't want to redefine the shape as a 4-array more than once.

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "file:shape.schema.json",
    "title": "shape JSON schema",
    "description": "Schema for validating the serialization of a shape object",
    "type": "array",
    "minItems": 4,
    "maxItems": 4,
    "items": {
        "type": "number"
    }
}

I'm trying to validate it using the following Python code:

import unittest
import json

from jsonschema import validate

class TestShapeFormat(unittest.TestCase):
    """
    Sanity checks for the shape schema
    """
    def setUp(self):
        with open("shape.schema.json") as f:
            self.schema = json.load(f)

    def test_shape_format(self):
        validate(instance={[1,2,3,4]}, schema=self.schema)

if __name__ == "__main__":
    unittest.main()

The problem is that when I run that, I get a TypeError: unhashable type: 'list' exception:

self = <test_shape_format.TestShapeFormat testMethod=test_shape_format>

    def test_shape_format(self):
>       validate(instance={[1,2,3,4]}, schema=self.schema)
E       TypeError: unhashable type: 'list'

tests/test_shape_format.py:21: TypeError

I'm using jsonschema 4.1.0.

Thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions