Skip to content

invalid-parameter-default error from generic with default of None #592

@samuelcolvin

Description

@samuelcolvin

Summary

Checking the following code

from typing import TypeVar

D = TypeVar('D')


def foo(x: D = None) -> D:
    return x

Gives

error[invalid-parameter-default]: Default value of type `None` is not assignable to annotated parameter type `D`
 --> ex.py:6:9
  |
6 | def foo(x: D = None) -> D:
  |         ^^^^^^^^^^^
7 |     return x
  |
info: rule `invalid-parameter-default` is enabled by default

This passes with pyright and IMHO should not cause an error.

Apologies if this is reported elsewhere, nothing came up with the search "invalid-parameter-default generic".

Version

ty 0.0.1-alpha.8 (c1337c9 2025-06-02)

Metadata

Metadata

Assignees

No one assigned

    Labels

    genericsBugs or features relating to ty's generics implementation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions