-
Notifications
You must be signed in to change notification settings - Fork 225
Description
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.