Thanks for the feedback.

I just realized, I may have used Final in the wrong way the whole time.

var: Final = 1  # reveals Literal[1]?
var: Final[int] = 1  # reveals builtins.int

I probably used the explicitly typed version when testing and playing around with Final that I got the wrong idea on how it works.
Rereading the mypy docs with hindsight, it is pretty explicit on difference between the two. It seems like intuition led me astray.

In that case, yes, Approach A boils down to naked Literal behaving almost the same way as Final. Which degrades this proposal to super low priority and changes the nature of things. This should probably be at most a QoL feature request for the type checker implementations to just add a "Consider using Final" to error messages when it encounters Literal without value.

Thank you.


---- ORIGINAL MESSAGE ----
Date:    2022-04-19 22:10:47 UTC+0200
From:    eric@traut.com
To:      typing-sig@python.org
Subject: [Typing-sig] Re: Simple syntax for Literal
As @Mehdi2277 mentioned, using a bare `Final` annotation addresses this use case already. It works fine if the expression on the RHS of the assignment is simple, such as a literal integer value (`1`) or the negation of an integer literal (`-1`).

I wouldn't recommend using more complex expressions on the RHS of a `Final` declaration, at least if this is part of a library, because inference results for more complex expressions can differ from one type checker to another.
_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/
Member address: dev@reggx.eu