Skip to content

Fix TODO: handle generic type parameters in _eval_nested_generic_alias #7

@AliiiBenn

Description

@AliiiBenn

Status: NEEDS INVESTIGATION

Current Code Location

typemap/type_eval/_eval_typing.py, line 402-422

@_eval_types_impl.register
def _eval_nested_generic_alias(
    obj: _AssociatedTypeGenericAlias, ctx: EvalContext
):
    base, alias = obj.__args__

    # TODO: what if it has parameters of its own

    named_args = dict(
        zip(
            (p.__name__ for p in base.__origin__.__type_params__),
            base.__args__,
            strict=False,
        )
    )
    # ...

Question

The TODO asks: "what if it has parameters of its own?"

This refers to the case where base (the first argument to the associated type) is itself a generic class with type parameters.

Investigation Needed

  1. What happens when base.__origin__.__type_params__ is not empty?
  2. Are there existing test cases that trigger this code path?
  3. Does the current implementation handle it correctly or is there a bug?

Suggested Approach

  1. Add test cases that would trigger _eval_nested_generic_alias with parameterized generics
  2. Verify if the current code handles this correctly
  3. If not, implement the fix

Resolution

This issue requires investigation before implementing a fix.

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