# Buggy code
def infer_params(cls: Type[T], constructor: Callable[..., T] = None) -> Dict[str, Any]:
    if cls == FromParams:
        return {}
    if constructor is None:
        constructor = cls.__init__

    signature = inspect.signature(constructor)
    parameters = dict(signature.parameters)

    has_kwargs = False
    for param in parameters.values():
        if param.kind == param.VAR_KEYWORD:
            has_kwargs = True

    if not has_kwargs:
        return parameters

    # "mro" is "method resolution order".  The first one is the current class, the next is the
    # first superclass, and so on.  We take the first superclass we find that inherits from
    # FromParams.
    super_class = None
    for super_class_candidate in cls.mro()[1:]:
        if issubclass(super_class_candidate, FromParams):
            super_class = super_class_candidate
            break
    if super_class:
        super_parameters = infer_params(super_class)
    else:
        super_parameters = {}

    return {
        **super_parameters,
        **parameters,
    }  # Subclass parameters overwrite superclass ones


# Traceback (RuntimeError)
Traceback (most recent call last):
File "tmp.py", line 10, in <module>
Foo.from_params(Params({"a": 2, "b": "hi"}))
File "/Users/evanw/AllenAI/allennlp/allennlp/common/from_params.py", line 610, in from_params
kwargs = create_kwargs(constructor_to_inspect, cls, params, **extras)
File "/Users/evanw/AllenAI/allennlp/allennlp/common/from_params.py", line 163, in create_kwargs
parameters = infer_params(cls, constructor)
File "/Users/evanw/AllenAI/allennlp/allennlp/common/from_params.py", line 140, in infer_params
super_parameters = infer_params(super_class)
File "/Users/evanw/AllenAI/allennlp/allennlp/common/from_params.py", line 139, in infer_params
raise RuntimeError("found a kwargs parameter with no inspectable super class")
RuntimeError: found a kwargs parameter with no inspectable super class

# Fixed code
def infer_params(cls: Type[T], constructor: Callable[..., T] = None) -> Dict[str, Any]:
    if constructor is None:
        constructor = cls.__init__

    signature = inspect.signature(constructor)
    parameters = dict(signature.parameters)

    has_kwargs = False
    var_positional_key = None
    for param in parameters.values():
        if param.kind == param.VAR_KEYWORD:
            has_kwargs = True
        elif param.kind == param.VAR_POSITIONAL:
            var_positional_key = param.name

    if var_positional_key:
        del parameters[var_positional_key]

    if not has_kwargs:
        return parameters

    # "mro" is "method resolution order".  The first one is the current class, the next is the
    # first superclass, and so on.  We take the first superclass we find that inherits from
    # FromParams.
    super_class = None
    for super_class_candidate in cls.mro()[1:]:
        if issubclass(super_class_candidate, FromParams):
            super_class = super_class_candidate
            break
    if super_class:
        super_parameters = infer_params(super_class)
    else:
        super_parameters = {}

    return {
        **super_parameters,
        **parameters,
    }  # Subclass parameters overwrite superclass ones