Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

weird behavior when importing os.path

I'm not quite sure this question belong to StackOverflow and not other SE website, but since it's python related I thought it might fit.

Recently, I started getting error in my IDE (details on my IDE below) - I get an error "cannot find reference 'path' in 'os.py'" Looking into os.py, I realize that os.path is just an alias for posixpath.py (on Linux) or ntpath.py (on Windows). Now, no change has been made to my python installation, and when running scripts that import os.path (or from it), they all run fine, so there is no actual error, just annoying warning in my IDE. I tried changing the project interpreter in the IDE and it didn't work. I also tried running from terminal with the said IDE, and it worked fine. Could it be a bug in PyCharm?

I looked online and couldn't find bug report or anyone struggling with the same problem.


PyCharm build details:

PyCharm 2018.1 (Community Edition) Build #PC-181.4203.547, built on March 26, 2018 JRE: 1.8.0_152-release-1136-b20 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Linux 4.7.0-0.bpo.1-amd64

like image 246
Elad Edri Avatar asked Apr 02 '18 19:04

Elad Edri


2 Answers

It's a bug that was fixed in 2018.1.1 https://youtrack.jetbrains.com/issue/PY-28764

like image 75
user2235698 Avatar answered Nov 07 '22 01:11

user2235698


I suppose it is a bug (or behavior) introduced in the very last version of PyCharm. Indeed, it has been happening to me since the last update I recently installed.

However, I temporary ignored these unresolved references in PyCharm to avoid the annoying and misleading warnings.

To do so, if you are importing os.path this way (e.g.):

from os.path import join

Go to PyCharm preferences -> Editor -> Inspections

Then, look for "Unresolved references" under "Python" and add the following entries:

  • os.path
  • join

Hope this helps, Giuliano

like image 43
gfor Avatar answered Nov 07 '22 01:11

gfor