Looks like in my PyCharm installation missing references & missing declarations are not highlighted and not found. I tried to check all inspection checkboxes, but it didn't help. I am not in the read mode (though I enabled highlighting in it).
If I create an empty project and type
where XXX is an undeclared variable, it does not get found by the inspection. Previously such variables have always been found and highlighted.
It started occurring after the machine with PyCharm and projects ran out of memory. Then the memory was freed and highlighting started behaving randomly (correct lines were highlighted on random reasons). I thought that some indexes/cache files could be corrupted, so I deleted .idea files, deleted all cached stuff in .config and reinstalled PyCharm. But while random highlighting stopped, error highlighting and discovery isn't working.
At some point it looked like it was solved by changing the way interpreter is linked. I replaced mamba environment that was loaded as a conda environment with the same environment loaded as a virtual environment....
PyCharm 2023.1.2 (Community Edition)
Build #PC-231.9011.38, built on May 16, 2023