python / python/mypy

Support for Final-as-default, like Rust

Open
#16,313 5 comments 20 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature topic-final
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Feature

If I want to follow "best practices", I've got to put a Final[ ] wrapper around most type hints I use. Could there be a mypy flag to assume every type hint is final unless it's got a Mut[ ] wrapper?

Would probably require a search-replace script to convert a project between the modes, but that doesn't sound too bad.

Pitch

Variables being constant when you won't need to change them is generally regarded as a good idea, right? This would make it easier, like Rust does.

I don't know about any of the mypy internals, but this doesn't strike me as too big a change?

Interface change would be a new --final-as-default flag.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files, tests, or entry points are named. Start by tracing how mypy handles existing Final annotations and command-line flags, then clarify the semantics of --final-as-default and the proposed Mut wrapper; done would require an agreed design and coverage for the new mode.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.