python / python/mypy

New setting "user_builtins_name": Ignore specific "name-defined" errors

Open
#18,932 5 comments 0 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

Adding a setting "user_builtins_name", or "builtins", that is a array of strings for which the error [name-defined] is ignored.

Pitch

It is possible to extend the list of builtins function, which can be very useful in some projects as we no longer need to import this function if it's used extensively in the rest of the project.

Example:

builtins.__dict__['prints'] = prints = PrefixedPrint()

builtins.__dict__['_'] = localization.gettext

Sadly, mypy don't support such exotic things. There is two solution:

  1. Analyzer all the code to add dynamically the "user builtins name"
  2. Add a user-controlled setting to globally ignore specific "name-defined" errors

The first would be the best, but also the harder to implement. The second would be easier to implement, but some ignored 'name-defined' error could be legitimate depending on the import and call stack. But since the very exotic and niche feature, the risks are low and we can assume that the user know what he do when he use this settings.

The use of a setting name that contain the word 'builtins' allows to explicitly specify the user case of such setting (when a generic "ignore_name_defined" could be misinterpreted and so misused)

Related Issues
#7931

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 related issue #7931 and mypy's existing configuration handling for name-defined diagnostics. Trace where these errors are produced and how settings are tested; done means a user-controlled builtins-name setting suppresses only the specified errors and is covered by appropriate tests and documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.