basedmypy icon indicating copy to clipboard operation
basedmypy copied to clipboard

Variables `Final` by default (`mutable` / `var`)

Open KotlinIsland opened this issue 4 years ago • 9 comments

a = 1
a = 2  # should be an error imo
a: var = 1
a = 2  # yeah, that's ok

KotlinIsland avatar Oct 27 '21 05:10 KotlinIsland

mut? what is this, rust?

KotlinIsland avatar Oct 27 '21 06:10 KotlinIsland

mut? what is this, rust?

good point, DetachHead said that mutable would be better, as it would scare people off from using it :DDDDD

KotlinIsland avatar Oct 29 '21 10:10 KotlinIsland

what about:

a: mutable = [1,2,3]
a = []  # error
a[0] = 2  # ok

b: var = [1,2,3]
b = []  # ok
b[0] = 2  # error

c: var[mutable] = [1,2,3]
c = []  # ok
c[0] = 2  # ok

KotlinIsland avatar Oct 29 '21 10:10 KotlinIsland

https://github.com/KotlinIsland/basedmypy/issues/45

KotlinIsland avatar Oct 29 '21 10:10 KotlinIsland

This issue has a few examples, but not much explanation.

  • Is this proposing a change to python itself, or just requiring every variable to have a type annotation?
  • Is it trying to solve a particular issue (eg. in the first example is a's type Literal[1] or int?)
  • What are var and mutable? new types?
  • Is #189 a duplicate of this issue?

Zeckie avatar Feb 20 '22 02:02 Zeckie

  • Is this proposing a change to python itself, or just requiring every variable to have a type annotation?

This is only a feature within basedmypy.

  • Is it trying to solve a particular issue (eg. in the first example is a's type Literal[1] or int?)

It's solving the issue of reassignable variables being the default option

  • What are var and mutable? new types?

Potentially

  • Is #189 a duplicate of this issue?

Similar, but is referring to final and is unrelated to Final

KotlinIsland avatar Feb 20 '22 07:02 KotlinIsland

Similar, but is referring to final and is unrelated to Final

what is final

DetachHead avatar May 29 '22 07:05 DetachHead

typing.final

KotlinIsland avatar May 29 '22 07:05 KotlinIsland

So this issue is for variables, #189 is for methods?

Zeckie avatar May 30 '22 12:05 Zeckie