basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

Invent a better `type`

Open KotlinIsland opened this issue 2 years ago • 4 comments

Something that represents type realm types, not instances of builtins.type. The same as TypeForm, but with a different name.

Issues with type:

  • Doesn't support TypeForms
  • Constructor signatures are unchecked
  • Requires special-casing (type[type])
  • The stubs don't mention the type parameter
  • type doesn't accept abstract types

KotlinIsland avatar Feb 29 '24 05:02 KotlinIsland

in the mean time i want to add a rule to ban type[T] syntax, because it's extremely unsafe

DetachHead avatar Feb 29 '24 05:02 DetachHead

What about just banning __call__ on types?

KotlinIsland avatar Feb 29 '24 23:02 KotlinIsland

Good idea. Then once we have intersections, we can just make a type alias that lets you specify its constructor parameters:

type Type[T, P] = type[T] & Callable[P, T]

DetachHead avatar Mar 01 '24 02:03 DetachHead

  • https://github.com/KotlinIsland/basedmypy/issues/628
  • https://github.com/python/mypy/issues/1831

KotlinIsland avatar Mar 18 '24 00:03 KotlinIsland