def extend_schema(schema, doc):
    schema_kind = get_kind(schema)
    doc_kind = get_kind(doc)

    # 1. anything + null => anything
    if doc_kind == "null":
        return schema
    if schema_kind == "null":
        return make_schema(doc)

    # 2. not-list => [not-list] when compared to a list
    if schema_kind != "list" and doc_kind == "list":
        schema_kind = "list"
        schema = [schema]
    if doc_kind != "list" and schema_kind == "list":
        doc_kind = "list"
        doc = [doc]

    # 3. not-dict => {'': not-dict} when compared to a dict
    if schema_kind != 'dict' and doc_kind == 'dict':
        if not schema_kind == 'string':
            raise SchemaInferenceError((schema, schema_kind) % "%r is type %r but should be type 'string'!!")
        schema_kind = 'dict'
        schema = {'': schema_kind}
    if doc_kind != 'dict' and schema_kind == 'dict':
        if not doc_kind == 'string':
            raise SchemaInferenceError("%r is type %r but should be type 'string'!!" % (doc, doc_kind))
        doc_kind = 'dict'
        doc = {'': doc_kind}

    # 4. Now that schema and doc are of the same kind
    if schema_kind == doc_kind == "dict":
        for key in doc:
            schema[key] = extend_schema(schema.get(key, None), doc[key])
        return schema
    if schema_kind == doc_kind == "list":
        for doc_ in doc:
            schema[0] = extend_schema(schema[0], doc_)
        return schema
    if schema_kind == doc_kind == "string":
            return "string"

    # 5. We should have covered every case above, but if not, fail hard
    raise SchemaInferenceError("Mismatched schema (%r) and doc (%r)" % (schema, doc))
dataset/ETHPy150Open dimagi/commcare-hq/corehq/ex-submodules/couchexport/schema.py/extend_schema/swapped operands of `%`