basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

"TypeVar constraint type cannot be generic" false positive / incorrect error message when generic defaults reference each other

Open DetachHead opened this issue 5 months ago • 3 comments

Description

Code sample in basedpyright playground

class Foo[T = Bar]:...

class Bar[T = Foo]:...

def foo[T: Bar](): ... # TypeVar constraint type cannot be generic (reportGeneralTypeIssues)

it's unclear to me whether there should actually be an error here (i think probably yes) but the error message is wrong

DetachHead avatar Oct 01 '25 00:10 DetachHead

i would have expected the Bar here to be Bar[Any], unless i'm missing something

KotlinIsland avatar Oct 01 '25 00:10 KotlinIsland

it would be Bar[Foo[Bar[Foo[...]]]], so i guess that would turn into Bar[Any] because it would otherwise be an infinite recursion that can't be resolved?

DetachHead avatar Oct 01 '25 00:10 DetachHead

oh, hmmmm, i did miss that 😅

we can't have infinitly recursive types? i thought they were supported?

type L = list[L]

KotlinIsland avatar Oct 01 '25 00:10 KotlinIsland