Skip to content

Fix eval_call_with_types vararg annotations#117

Open
iliyasone wants to merge 2 commits into
vercel:mainfrom
iliyasone:main
Open

Fix eval_call_with_types vararg annotations#117
iliyasone wants to merge 2 commits into
vercel:mainfrom
iliyasone:main

Conversation

@iliyasone
Copy link
Copy Markdown

eval_call_with_types accepts individual type objects as positional and keyword arguments, but its annotation described each *arg as a tuple and each **kwarg value as a dict. That made mypy reject valid calls such as eval_call_with_types(func, User) and encouraged tuple-wrapping that does not match the runtime binding contract.

Update the public signature to annotate each supplied type object directly and add a regression test that is checked by the mypy test harness for both positional and keyword type objects.

Validation:

uv run pytest
# test will fail if undo the change
uv run ruff check .
uv run ruff format --check .

Now something like this will not fail mypy check:

import typemap_extensions as typing
from typemap.type_eval import eval_call_with_types, format_helper


class FieldArgs(TypedDict, total=False):
    default: ReadOnly[object]
    alias: ReadOnly[str]


class Field[T: FieldArgs](typing.InitField[T]):
    pass


type ModelDump[T] = typing.NewTypedDict[
    *[typing.Member[field.name, field.type] for field in typing.Iter[typing.Attrs[T]]]
]

class BaseModel:
    def model_dump[T: BaseModel](self: T) -> ModelDump[T]:
        return cast(ModelDump[T], self.__dict__)

if __name__ == "__main__":
    model_dump_return = eval_call_with_types(BaseModel.model_dump, User)
    print(format_helper.format_class(model_dump_return))

iliyasone added 2 commits May 18, 2026 22:22
eval_call_with_types accepts individual type objects as positional and keyword arguments, but its annotation described each *arg as a tuple and each **kwarg value as a dict. That made mypy reject valid calls such as eval_call_with_types(func, User) and encouraged tuple-wrapping that does not match the runtime binding contract.

Update the public signature to annotate each supplied type object directly and add a regression test that is checked by the mypy test harness for both positional and keyword type objects.

Validation: uv run pytest; uv run ruff check .; uv run ruff format --check .; uv run mypy --config-file pyproject.toml typemap
The eval_call_with_types regression tests need typed pytest function bodies so mypy checks the calls inside them. Without return annotations, mypy skips those bodies under the current config, so reverting the public signature is not caught by the mypy harness.

Annotate the regression test functions with -> None. Verified that the old tuple/dict vararg signature now fails both direct mypy on the test file and the pytest-driven mypy harness, while the fixed signature passes.

Validation: uv run pytest; uv run ruff check .; uv run ruff format --check .; uv run mypy --config-file pyproject.toml tests/test_eval_call_with_types_signature.py
@vercel
Copy link
Copy Markdown

vercel Bot commented May 18, 2026

@iliyasone is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant