Thank you so much for producing Pylance - it's amazingly fast and I really love the grayed out unused imports! :+1: :1st_place_medal:
Pylance recognises walrus operator and correctly parses code containing it
Pylance doesn't recognise walrus operator and throws up errors/warnings
This is a little helper class that's useful for getting the right version of metadata that change over time.
It's got a couple of walrus operators in it but it works without issues in Python 3.8.
class NearestKeyDict(collections.UserDict):
"""Dictionary for looking up nearest key to a given key.
Useful for 'nearest date' lookups but can work for any keys implementing <= >=
Based on https://stackoverflow.com/a/3387975/13088500
"""
def __init__(self, data={}, how="max_before"):
self.data = data
self.how = how
def __getitem__(self, key):
return self.data[self._keytransform(key)]
def __setitem__(self, key, value):
self.data[self._keytransform(key)] = value
def __delitem__(self, key):
del self.data[self._keytransform(key)]
def _keytransform(self, key):
if self.how != "min_after":
if len(candidate_keys := [k for k in sorted(self.data) if k <= key]):
return max(candidate_keys)
else:
raise KeyError(f"No data key found before {key}")
else:
if len(candidate_keys := [k for k in sorted(self.data) if k >= key]):
return min(candidate_keys)
else:
raise KeyError(f"No data key found after {key}")

Thanks for the bug report. I've fixed the bug, and the fix will be in an upcoming version of Pylance.
Thank you so much - that was amazingly fast!!
This issue has been fixed in version 2020.7.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202070-9-july-2020
Most helpful comment
Thanks for the bug report. I've fixed the bug, and the fix will be in an upcoming version of Pylance.