python / python/mypy

Disallow formatting None into f-string

Open
#12,599 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Feature

Code like this should be an error, if some option is turned on:

foo: str | None = None
print(f"blah blah {foo}")

Pitch

When reviewing code like this, I manually check whether foo can be None. For example, you don't want a user interface to display There are None active users, or Do you want to delete 'None'?.

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

Start from the issue's f-string example and inspect how mypy currently checks values interpolated into f-strings. Determine how the proposed opt-in behavior should report a possibly-None value and what tests are needed to cover accepted and rejected cases.

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
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.