python / python/mypy

Provide the full parsed config file to each plugin

Open
#20,113 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Feature

Provide the full parsed config file to each plugin

Pitch

Currently, Mypy plugins are passed only the Options object in their constructor, which captures Mypy options but not Mypy plugin options. Consequently, each plugins has to re-parse the file. This is a waste of time, may add to the necessary dependencies for a plugin with configuration, and requires re-implementing the logic for parsing different file types (TOML vs config). Here's an example of the pydantic plugin doing just this:

https://github.com/pydantic/pydantic/blob/06448aa41764d0c1e1c2f9455b108c4b21012929/pydantic/v1/mypy.py#L239-L256

The neatest solution would be to pass the full config object to the constructor. Unfortunately, this would be a breaking change to the constructor signature, so probably the more palatable option would be to store the config options within each Plugin instance (in the constructor), which the subclasses can use if they want:

class SomeMypyPlugin(Plugin):
    def __init__(self, options: Options) -> None:
        super().__init__(options)
        my_config_option = self.raw_config["tools"]["some_mypy_plugin"]
        # use my_config_option

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 at the Plugin constructor and the configuration-loading path, then compare the pydantic plugin example linked in the issue. Trace how Options and plugin configuration are currently parsed, and define completion as making the full parsed configuration available to plugin instances without requiring each plugin to re-parse TOML or config files.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
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.