• Register
2 votes
313 views

Problem:

I am new in python programming an I am using Jet Brains Pycharm IDE.
In pycharm I have program organized like:
 Sources
   |--__init__.py
   |--Additions
      |--__init__.py
      |--Add.py
   |--Collaboration
      |--__init__.py
      |--Colab.py
   |--Views
      |--__init__.py
      |--views.py
   |--Model
      |--__init__.py
      |--Models.py

But there is an warning that always appear:

Cannot find reference 'Add' in __init__.py

Why is this warning always appear please help

10 7 2
6,050 points

2 Answers

2 votes

Answer:

Looks like this issue will pop up again if one use a remote environment in PyCharm, because PyCharm somehow forget to sync these *.pyi files to the local remote storage.
Solution: Manually mapping the local remote storage to the remote path, then sync *.pyifiles to local would solve these problem.

Plz spread this tip so nobody suffer from these annoying falsify inspection warning again

PyCharm has its share of small bugs like this, but in my opinion its benefits far outweigh its drawbacks. If you'd like to try another good IDE, there's also Spyder/Spyderlib.

You can locate the path to local storage at the Project View -> External Libraries -> Your Environment -> Remote Libraries, then right click and choose "Copy Path"

Please look out if there is any update in you IDE.

If this helps you let me know.

 

 

11 6 4
34,930 points
0 votes

Solution:

I guess this is a bug in pycharm. PyCharm exhibits to be expecting the referenced module to be added in an __all__ = [] statement.

For precise coding etiquette, must you include the __all__ statement from your modules? this is really the question we hear young Spock answering while he was being tested, to which he responded: "It is morally praiseworthy however not morally obligatory."

To get around it, you can easily disable that  (highly helpfulful) inspection globally, or inhibit it for the earmarked function or statement.

To do so:

  • Place the caret over the erroring text ('choice', from your example above)

  • Educate the intention menu (alt-enter by default, mine is set to alt-backspace)

  • Press the right arrow to open the submenu, and choose the relevant action

PyCharm has its share of small bugs like this, however in my view its benefits far outweigh its drawbacks. In case you'd like to attempt another good IDE, there's also Spyder/Spyderlib.

I know this is quite a bit after you asked your question, however I hope this helps.

Edited: Generally, I conceived that this was earmarked to checking __all__, however it seems like it's the more general 'Unresolved References' check, which can be very helpful. It's likely best to employ statement-level disabling of the feature, either by employing the menu as mentioned above, or by earmarked # noinspection PyUnresolvedReferences on the line preceding the statement.

You must first take a look at this. This interprets what occurs at the time you import a package. For convenience:

The import statement conduct the following convention: in case a package’s __init__.py code defines a list named __all__, it is taken to be the list of module names that must be imported when from package import * is encountered. It is up to the package author to keep this list up-to-date at the time a fresh version of the package is released. Package authors may also fix not to support it, in case they don’t see a use for importing * from their package.

Hence PyCharm respects this by displaying a warning message, so that the author can decide which of the modules get imported when * from the package is imported. Thus this appears to be helpful property of PyCharm (and in no way can it be named a bug, I suppose). You can simply remove this warning by including the names of the modules to be imported at the time your package is imported in the __all__ variable which is list, like this

__init__.py

from . import MyModule1, MyModule2, MyModule3
__all__ = [MyModule1, MyModule2, MyModule3]

Afterwards you include this, you can ctrl+click on these module names used in any other part of your project to directly jump to the declaration, which I often find very helpful.

10 6 4
31,120 points

Related questions

1 vote
1 answer 16 views
16 views
Problem: I have a program that is organized like: Sources |--__init__.py |--Additions |--__init__.py |--Add.py |--Collaboration |--__init__.py |--Colab.py |--Views |--__init__.py |--views.py |--Model |--__init__.py |--Models.py Can anybody explain me the “__init__.py” that is in every file?
asked May 4 samhaz 5k points
1 vote
1 answer 96 views
96 views
Problem: I have recently started learning file handling with Python. I am currently having the folder which is full of pdf files. My task is to remove all the spaces from all the file names and then try to replace them with the underscores. Please find below the code ... my issue, but I have tried to look all over and still unable to find the solution for my above error related to file handling.
asked Jun 2 Martin K 6.6k points
0 votes
1 answer 38 views
38 views
Problem: I have freshly migrated my project from the old python2 to the new python3 and it has hundreds of the ForeignKey relations. I have very basic knowledge related to python. Using a solution to go line by line and add on_delete argument is not the possible. What ... it does not look like catching it somehow. Looking for a Python expert who can try to fix my above Python error very quickly.
asked Jul 15 Raphael Pacheco 4.9k points
1 vote
1 answer 147 views
147 views
Problem : I am a Computer Science Student. I want to develop my website by using Django 2.1.3 and python 3.7.1. If I try to go to my websites homepage then i often face below error: Traceback: File "C:\Users\Martin\AppData\Local\Programs\Python\ ... TypeError at / Exception Value: __init__() takes 1 positional argument but 2 were given Please guide me in fixing my above django related error.
asked May 14 Martin K 6.6k points