basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

bare literal types

Open DetachHead opened this issue 2 years ago • 1 comments

foo: True
bar: 1 | 2

DetachHead avatar Jan 24 '24 02:01 DetachHead

and Enums

KotlinIsland avatar Aug 28 '24 00:08 KotlinIsland

This would be really nice for typing fixed-size arrays/vectors/matrices/etc.

Similarly, supporting Ellipses ... would be quite useful.

Is this on the roadmap?

anadodik avatar Jun 19 '25 20:06 anadodik

adding non-standard syntax like this isn't super high priority for me, i consider fixing false positives/false negatives and language server features to be more important. however if someone wants to implement it a PR is welcome, as long as there's an option to ban it for users who either can't or don't want to use non-standard syntax in their projects

DetachHead avatar Jun 26 '25 12:06 DetachHead

pyright already supports bare literals:

class A[T]:
    def __init__(self, t: T) -> None:
        pass

B = A[1]
b: B = A(2)

KotlinIsland avatar Sep 23 '25 04:09 KotlinIsland

that behavior is not intentional and is therefore completely broken

Code sample in basedpyright playground

class A[T]:
    def __init__(self, t: T) -> None:
        pass

B = A[1 | 2]
b: B = A(2) # error: "int" is not assignable to type "Literal[3]"

DetachHead avatar Sep 23 '25 13:09 DetachHead