Skip to content

Messed plugin config list order #677

Description

@dhanak

Hi!

TL;DR

I think that merge_dicts implementation in _utils.py is wrong:

def merge_dicts(dict_a, dict_b):
    """Recursively merge dictionary b into dictionary a.

    If override_nones is True, then
    """

    def _merge_dicts_(a, b):
        for key in set(a.keys()).union(b.keys()):
            if key in a and key in b:
                if isinstance(a[key], dict) and isinstance(b[key], dict):
                    yield (key, dict(_merge_dicts_(a[key], b[key])))
                elif isinstance(a[key], list) and isinstance(b[key], list):
                    yield (key, list(set(a[key] + b[key]))) # <--- this line here is wrong
                elif b[key] is not None:
                    yield (key, b[key])
                else:
                    yield (key, a[key])
            elif key in a:
                yield (key, a[key])
            elif b[key] is not None:
                yield (key, b[key])

    return dict(_merge_dicts_(dict_a, dict_b))

By converting the list to a set, it not only gets rid of the duplicates, but also messes up the list order unpredictably. Replacing set() with OrderedDict.fromkeys() seems to fix the issue described in detail below.


I'm using pylsp v1.13.1 with pylsp_mypy v0.7.0. (The whole LSP is run by Emacs v30.1 via eglot, but this probably doesn't matter.) And I noticed the following strange behavior, which I can't really put my finger on yet.

When pylsp invokes pylsp_mypy, it uses the following configuration:

[stderr]  2025-10-08 12:21:46,942 CEST - INFO - pylsp.config.config - Updated settings to {'plugins': {'jedi': {'environment': '/home/david/pyproj/.venv'}, 'ruff': {'executable': '/home/david/pyproj/.venv/bin/ruff'}, 'pylsp_mypy': {'overrides': ['--python-executable', '/home/david/pyproj/.venv/bin/python', True]}, 'flake8': {'executable': None}, 'pylint': {'executable': None}}}

Note the overrides list. The next log line after this, however, is this:

[stderr]  2025-10-08 12:21:47,475 CEST - INFO - pylsp_mypy.plugin - lint settings = {'overrides': [True, '/home/david/pyproj/.venv/bin/python', '--python-executable']} document.path = /home/david/pyproj/src/pyproj/__init__.py is_saved = False

Note how the overrides list is in reverse order. And right enough, mypy refuses to run:

error: argument --python-executable: expected one **argument**

I also noticed that it's not always reverse, the order seems to be pretty random. Sometimes it's ok and works, other times, it's messed up.

Activity

  1. changed the title [-]Strangely reversed plugin config list order[/-] [+]Messed plugin config list order[/+] on Oct 8, 2025
  2. georgek commented on Aug 4, 2026

    @georgek

    I'm getting the same nondeterministic behaviour.

    Using this to remove duplicates from a command line is surely wrong anyway? Two parameters might have the same option, like --arg1 val --arg2 val. It's not valid to dedupe val in this case.

    Why are they being deduped anyway? Programs can often deal with cmdline parameters being duplicated and if they can't this would be seen as an error when running.

  3. dhanak commented on Aug 4, 2026

    @dhanak
    Author

    I switched to using ruff server and ty server via rassumfrassum. It provides a very smooth experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions