Skip to content

Unable to specify a default value for a generic parameter #3737

Description

@rowillia

Simplified Example:

fromtypingimportTypeVar_T=TypeVar('_T')
deffoo(a: _T=42) ->_T: # E: Incompatible types in assignment (expression has type "int", variable has type "_T")returna

Real World example is something closer to:

_T=TypeVar('_T')
defnoop_parser(x: str) ->str:
returnxdeffoo(value: str, parser: Callable[[str], _T] =noop_parser) ->_T:
returnparser(value)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions