KotlinIsland / basedmypy

Based Python static type checker with baseline, sane default settings and based typing features
Other
120 stars 4 forks source link

immutable collections by default (`mutable`/covariant/protocol/nominal) #45

Open KotlinIsland opened 2 years ago

KotlinIsland commented 2 years ago

Using Sequence when you want an covariant or immutable list is not always optimal.

We propose:

such that

Sequence
↑
ListLike
↑
list
↑
mutable[list]

A collection coming from third party code (inc std) would always be a mutable[list].

Zeckie commented 2 years ago

Making collections immutable by default will be a pretty major change. Are you proposing a new language, forked from python?

KotlinIsland commented 2 years ago

Making collections immutable by default will be a pretty major change. Are you proposing a new language, forked from python?

Making collections immutable for static analysis purposes only, similar to making classes final by default, this will have no effect on any runtime behaviour, ie:

[0][0]=0

Would get a static error, but would run and complete without issue.