Skip to content

Provide the full parsed config file to each plugin #20113

@multimeric

Description

@multimeric

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    featuretopic-pluginsThe plugin API and ideas for new plugins

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions