Warnings don't work about unresolved references after using development install
Asked Answered
V

3

2

I have a bug with PyCharm, after I use development install pip install -v -e . the IDE does not warn me about any unresolved references. For example, with unresolved references normally you get this:

screenshot unresolved reference

But now after development install unresolved references don't give any warnings (for any names, functions, variables, modules...):

screenshot without unresolved reference

I think this bug was triggered after I named a module by mistake with a dash (in setup.py) and installed it, like this:

entry_points={
    "console_scripts": [
        "adapt-entry = adapt.entry.point-of-entry:run_program",
    ],

It installed at first, after a while the IDE warned the name was illegal. But after I changed the name to use underscores instead of the dashs the reference inspections of the IDE had become broken for all projects and interpreters if I use development install.

I tried all the usual solutions from this list for reference errors (invalidating cache, deleting .idea folder, new venv, changing interpreter, restart, reboot, etc...). But except clearing IDE wide user preferences (I want to avoid it) or reinstalling the IDE (even worse) I tried everything on the list and nothing solved the problem. For all effects my reference inspections are broken the moment I use development install.

I'm using the usual src layout with a minimal setup.py and a regular venv, the following file and directory structure:

C:.
adapt
├───src
│    ├───data
│    ├─  __init__.py
│    │
│    ├───entry
│    ├─  point_of_entry.py
│    └─  __init__.py
│
setup.py

and a minimal setup.py

setup(
    name='adapt',
    version='0.1',
    package_dir={'': 'src'},
    zip_safe=False,
    packages=find_packages(where='src'),
    package_data={
        "adapt.data": ["*.txt", "*.csv"],
        'adapt': ['py.typed'],
    },
    include_package_data=True,
    entry_points={
        "console_scripts": [
            "adapt_entry = adapt.entry.point_of_entry:run_program",
        ],
      }
),

The more common error is references not resolving, but in this case it's the opposite: the code runs and finds the references. The problem is (as shown in the 2nd screenshots) it doesn't warn about any unresolved references I introduce on purpose.

But when I run an inspection all the other warnings seem to be issued correctly. (I think I have the proper inspections activated, shown in the screenshot below.) How to solve this short wiping IDE wide user preferences or reinstalling the IDE altogether? Could there be some indirect cause I'm failing to realize?

IDE settings of inspections

Vd answered 20/3, 2021 at 12:27 Comment(1)
Ok, apparently I just found a way to solve it. Change the inspection from warning to error and disable reader mode should issue the necessary error with the red scribble. I still welcome a better explanation to the question.Vd
U
4

It is caused by the Reader mode, please vote for https://youtrack.jetbrains.com/issue/PY-45708 (thumbs up near the title)

Unbated answered 22/3, 2021 at 8:48 Comment(1)
Excellent link it explains everything authoritatively.Vd
S
2

Just to extend @user2235698 answer, this is happened to me too due to Reader mode being activated in my IDE.

You can easily disable this by:

  • Open the settings (ctrl + alt + s)
  • Search for "Reader Mode" in the search box or navigate to Editor | Reader Mode
  • Disable the Enable Reader Mode option
  • Click on apply
Smoking answered 4/5, 2021 at 15:23 Comment(0)
N
1

Not directly answering the OP's question but posting here as it may help others who, like me, found this page when PyCharm wasn't highlighting unresolved references.

The problem was that I had syntax highlighting turned off at the top-right of the file

enter image description here

Selecting Syntax or All Problems will highlight things again. Oh PyCharm you are so logical and intuitive!

I'm using PyCharm 2022.3.2 (Professional Edition).

Neill answered 23/3, 2023 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.