python / python/mypy

Consider adding `--non-numeric-bool` mode

Open
#8,363 10 comments 29 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

As it was discussed in https://github.com/python/mypy/issues/8069, sometimes we need to logically separate int and bool types.

Currently mypy allows this to happen:

def some(a: int): ...

some(x > 1)

Because bool is subtype of int. I am proposing to add a strict-bool mode, so bool would be treated as a non-int type. And this code would generate an error.

It can be a new config option: --strict-bool or a new disabled by default error code in the future as @JukkaL suggested.

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 by reviewing the discussion in issue #8069 and the example showing bool passed to an int parameter. Determine the intended behavior and whether it should be a --strict-bool configuration option or a disabled error code. Done means the example is rejected when the feature is enabled while existing behavior remains unchanged by default.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.