# Buggy code
def __new__(mcs, name, bases, namespace, **kwargs):  # noqa C901
    fields: Dict[str, ModelField] = {}
    config = BaseConfig
    validators: "ValidatorListDict" = {}

    pre_root_validators, post_root_validators = [], []
    private_attributes: Dict[str, ModelPrivateAttr] = {}
    slots: Set[str] = namespace.get("__slots__", ())
    slots = {slots} if isinstance(slots, str) else set(slots)

    for base in reversed(bases):
        if (
            _is_base_model_class_defined
            and issubclass(base, BaseModel)
            and base != BaseModel
        ):
            fields.update(smart_deepcopy(base.__fields__))
            config = inherit_config(base.__config__, config)
            validators = inherit_validators(base.__validators__, validators)
            pre_root_validators += base.__pre_root_validators__
            post_root_validators += base.__post_root_validators__
            private_attributes.update(base.__private_attributes__)

    config = inherit_config(namespace.get("Config"), config)
    validators = inherit_validators(extract_validators(namespace), validators)
    vg = ValidatorGroup(validators)

    for f in fields.values():
        f.set_config(config)
        extra_validators = vg.get_validators(f.name)
        if extra_validators:
            f.class_validators.update(extra_validators)
            # re-run prepare to add extra validators
            f.populate_validators()

    prepare_config(config, name)

    class_vars = set()
    if (namespace.get("__module__"), namespace.get("__qualname__")) != (
        "pydantic.main",
        "BaseModel",
    ):
        annotations = resolve_annotations(
            namespace.get("__annotations__", {}), namespace.get("__module__", None)
        )
        untouched_types = UNTOUCHED_TYPES + config.keep_untouched
        # annotation only fields need to come first in fields
        for ann_name, ann_type in annotations.items():
            if is_classvar(ann_type):
                class_vars.add(ann_name)
            elif is_valid_field(ann_name):
                validate_field_name(bases, ann_name)
                value = namespace.get(ann_name, Undefined)
                allowed_types = (
                    get_args(ann_type) if get_origin(ann_type) is Union else (ann_type,)
                )
                if (
                    isinstance(value, untouched_types)
                    and ann_type != PyObject
                    and not any(
                        lenient_issubclass(get_origin(allowed_type), Type)
                        for allowed_type in allowed_types
                    )
                ):
                    continue
                fields[ann_name] = inferred = ModelField.infer(
                    name=ann_name,
                    value=value,
                    annotation=ann_type,
                    class_validators=vg.get_validators(ann_name),
                    config=config,
                )
            elif ann_name not in namespace and config.underscore_attrs_are_private:
                private_attributes[ann_name] = PrivateAttr()

        for var_name, value in namespace.items():
            can_be_changed = var_name not in class_vars and not isinstance(
                value, untouched_types
            )
            if isinstance(value, ModelPrivateAttr):
                if not is_valid_private_name(var_name):
                    raise NameError(
                        f'Private attributes "{var_name}" must not be a valid field name; '
                        f'Use sunder or dunder names, e. g. "_{var_name}" or "__{var_name}__"'
                    )
                private_attributes[var_name] = value
            elif (
                config.underscore_attrs_are_private
                and is_valid_private_name(var_name)
                and can_be_changed
            ):
                private_attributes[var_name] = PrivateAttr(default=value)
            elif (
                is_valid_field(var_name)
                and var_name not in annotations
                and can_be_changed
            ):
                validate_field_name(bases, var_name)
                inferred = ModelField.infer(
                    name=var_name,
                    value=value,
                    annotation=annotations.get(var_name, Undefined),
                    class_validators=vg.get_validators(var_name),
                    config=config,
                )
                if var_name in fields and inferred.type_ != fields[var_name].type_:
                    raise TypeError(
                        f"The type of {name}.{var_name} differs from the new default value; "
                        f"if you wish to change the type of this field, please use a type annotation"
                    )
                fields[var_name] = inferred

    _custom_root_type = ROOT_KEY in fields
    if _custom_root_type:
        validate_custom_root_type(fields)
    vg.check_for_unused()
    if config.json_encoders:
        json_encoder = partial(custom_pydantic_encoder, config.json_encoders)
    else:
        json_encoder = pydantic_encoder
    pre_rv_new, post_rv_new = extract_root_validators(namespace)

    exclude_from_namespace = fields | private_attributes.keys() | {"__slots__"}
    new_namespace = {
        "__config__": config,
        "__fields__": fields,
        "__validators__": vg.validators,
        "__pre_root_validators__": unique_list(pre_root_validators + pre_rv_new),
        "__post_root_validators__": unique_list(post_root_validators + post_rv_new),
        "__schema_cache__": {},
        "__json_encoder__": staticmethod(json_encoder),
        "__custom_root_type__": _custom_root_type,
        "__private_attributes__": private_attributes,
        "__slots__": slots | private_attributes.keys(),
        **{n: v for n, v in namespace.items() if n not in exclude_from_namespace},
    }

    cls = super().__new__(mcs, name, bases, new_namespace, **kwargs)
    # set __signature__ attr only for model class, but not for its instances
    cls.__signature__ = ClassAttribute(
        "__signature__", generate_model_signature(cls.__init__, fields, config)
    )
    return cls


# Traceback (TypeError)
from pydantic import BaseModel, Field
from typing import Callable
class Foo(BaseModel):
...     # without default value, getting user warning
...     callback: Callable[[], dict]
...
Foo.schema()
__main__:1: UserWarning: Callable callback was excluded from schema since JSON schema has no equivalent type.
{'title': 'Foo', 'type': 'object', 'properties': {}}

class FooDefault(BaseModel):
...     callback: Callable[[], dict] = Field(default=lambda: {'some': 'data'})
FooDefault.schema()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pydantic/main.py", line 637, in pydantic.main.BaseModel.schema
File "pydantic/schema.py", line 153, in pydantic.schema.model_schema
File "pydantic/schema.py", line 523, in pydantic.schema.model_process_schema
File "pydantic/schema.py", line 564, in pydantic.schema.model_type_schema
File "pydantic/schema.py", line 215, in pydantic.schema.field_schema
File "pydantic/schema.py", line 183, in pydantic.schema.get_field_info_schema
File "pydantic/schema.py", line 846, in pydantic.schema.encode_default
File "pydantic/json.py", line 65, in pydantic.json.pydantic_encoder
TypeError: Object of type 'function' is not JSON serializable

# Fixed code
def __new__(mcs, name, bases, namespace, **kwargs):  # noqa C901
    fields: Dict[str, ModelField] = {}
    config = BaseConfig
    validators: "ValidatorListDict" = {}

    pre_root_validators, post_root_validators = [], []
    private_attributes: Dict[str, ModelPrivateAttr] = {}
    slots: Set[str] = namespace.get("__slots__", ())
    slots = {slots} if isinstance(slots, str) else set(slots)

    for base in reversed(bases):
        if (
            _is_base_model_class_defined
            and issubclass(base, BaseModel)
            and base != BaseModel
        ):
            fields.update(smart_deepcopy(base.__fields__))
            config = inherit_config(base.__config__, config)
            validators = inherit_validators(base.__validators__, validators)
            pre_root_validators += base.__pre_root_validators__
            post_root_validators += base.__post_root_validators__
            private_attributes.update(base.__private_attributes__)

    config = inherit_config(namespace.get("Config"), config)
    validators = inherit_validators(extract_validators(namespace), validators)
    vg = ValidatorGroup(validators)

    for f in fields.values():
        f.set_config(config)
        extra_validators = vg.get_validators(f.name)
        if extra_validators:
            f.class_validators.update(extra_validators)
            # re-run prepare to add extra validators
            f.populate_validators()

    prepare_config(config, name)

    class_vars = set()
    if (namespace.get("__module__"), namespace.get("__qualname__")) != (
        "pydantic.main",
        "BaseModel",
    ):
        annotations = resolve_annotations(
            namespace.get("__annotations__", {}), namespace.get("__module__", None)
        )
        # annotation only fields need to come first in fields
        for ann_name, ann_type in annotations.items():
            if is_classvar(ann_type):
                class_vars.add(ann_name)
            elif is_valid_field(ann_name):
                validate_field_name(bases, ann_name)
                value = namespace.get(ann_name, Undefined)
                allowed_types = (
                    get_args(ann_type) if get_origin(ann_type) is Union else (ann_type,)
                )
                if (
                    isinstance(value, ANNOTATED_FIELD_UNTOUCHED_TYPES)
                    and ann_type != PyObject
                    and not any(
                        lenient_issubclass(get_origin(allowed_type), Type)
                        for allowed_type in allowed_types
                    )
                ):
                    continue
                fields[ann_name] = ModelField.infer(
                    name=ann_name,
                    value=value,
                    annotation=ann_type,
                    class_validators=vg.get_validators(ann_name),
                    config=config,
                )
            elif ann_name not in namespace and config.underscore_attrs_are_private:
                private_attributes[ann_name] = PrivateAttr()

        untouched_types = UNTOUCHED_TYPES + config.keep_untouched
        for var_name, value in namespace.items():
            can_be_changed = var_name not in class_vars and not isinstance(
                value, untouched_types
            )
            if isinstance(value, ModelPrivateAttr):
                if not is_valid_private_name(var_name):
                    raise NameError(
                        f'Private attributes "{var_name}" must not be a valid field name; '
                        f'Use sunder or dunder names, e. g. "_{var_name}" or "__{var_name}__"'
                    )
                private_attributes[var_name] = value
            elif (
                config.underscore_attrs_are_private
                and is_valid_private_name(var_name)
                and can_be_changed
            ):
                private_attributes[var_name] = PrivateAttr(default=value)
            elif (
                is_valid_field(var_name)
                and var_name not in annotations
                and can_be_changed
            ):
                validate_field_name(bases, var_name)
                inferred = ModelField.infer(
                    name=var_name,
                    value=value,
                    annotation=annotations.get(var_name, Undefined),
                    class_validators=vg.get_validators(var_name),
                    config=config,
                )
                if var_name in fields and inferred.type_ != fields[var_name].type_:
                    raise TypeError(
                        f"The type of {name}.{var_name} differs from the new default value; "
                        f"if you wish to change the type of this field, please use a type annotation"
                    )
                fields[var_name] = inferred

    _custom_root_type = ROOT_KEY in fields
    if _custom_root_type:
        validate_custom_root_type(fields)
    vg.check_for_unused()
    if config.json_encoders:
        json_encoder = partial(custom_pydantic_encoder, config.json_encoders)
    else:
        json_encoder = pydantic_encoder
    pre_rv_new, post_rv_new = extract_root_validators(namespace)

    exclude_from_namespace = fields | private_attributes.keys() | {"__slots__"}
    new_namespace = {
        "__config__": config,
        "__fields__": fields,
        "__validators__": vg.validators,
        "__pre_root_validators__": unique_list(pre_root_validators + pre_rv_new),
        "__post_root_validators__": unique_list(post_root_validators + post_rv_new),
        "__schema_cache__": {},
        "__json_encoder__": staticmethod(json_encoder),
        "__custom_root_type__": _custom_root_type,
        "__private_attributes__": private_attributes,
        "__slots__": slots | private_attributes.keys(),
        **{n: v for n, v in namespace.items() if n not in exclude_from_namespace},
    }

    cls = super().__new__(mcs, name, bases, new_namespace, **kwargs)
    # set __signature__ attr only for model class, but not for its instances
    cls.__signature__ = ClassAttribute(
        "__signature__", generate_model_signature(cls.__init__, fields, config)
    )
    return cls