Skip to content

default argument for generic function #2078

Closed
@naphatkrit

Description

@naphatkrit

I'm trying to do something like this:

T = TypeVar('T')

def identity(string):
  # type: (str) -> str
  return string

def f(normalize=identity):
  # type: (Callable[[str], T] -> str)

But mypy says this does not type-check. After adding a cast (normalize=cast(Any, identity), or even normalize=cast(Callable[[str], T], identity), this works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions