Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
d9b5e61d
Commit
d9b5e61d
authored
9 years ago
by
Valentina Kiryushkina
Browse files
Options
Download
Email Patches
Plain Diff
PY-14234 Fix false positive when underscored module imported inside the package
parent
2e2eed7f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java
+12
-1
...rains/python/inspections/PyProtectedMemberInspection.java
python/testData/inspections/PyProtectedMemberInspection/importFromTheSamePackage/my_package/__init__.py
+0
-0
...nspection/importFromTheSamePackage/my_package/__init__.py
python/testData/inspections/PyProtectedMemberInspection/importFromTheSamePackage/my_package/_package_internal_module.py
+2
-0
...FromTheSamePackage/my_package/_package_internal_module.py
python/testData/inspections/PyProtectedMemberInspection/importFromTheSamePackage/my_package/my_public_module.py
+3
-0
...n/importFromTheSamePackage/my_package/my_public_module.py
python/testSrc/com/jetbrains/python/inspections/PyProtectedMemberInspectionTest.java
+9
-0
...s/python/inspections/PyProtectedMemberInspectionTest.java
with
26 additions
and
1 deletion
+26
-1
python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java
+
12
-
1
View file @
d9b5e61d
...
@@ -21,6 +21,7 @@ import com.intellij.codeInspection.ProblemHighlightType;
...
@@ -21,6 +21,7 @@ import com.intellij.codeInspection.ProblemHighlightType;
import
com.intellij.codeInspection.ProblemsHolder
;
import
com.intellij.codeInspection.ProblemsHolder
;
import
com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel
;
import
com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel
;
import
com.intellij.openapi.util.text.StringUtil
;
import
com.intellij.openapi.util.text.StringUtil
;
import
com.intellij.psi.PsiDirectory
;
import
com.intellij.psi.PsiElement
;
import
com.intellij.psi.PsiElement
;
import
com.intellij.psi.PsiElementVisitor
;
import
com.intellij.psi.PsiElementVisitor
;
import
com.intellij.psi.PsiReference
;
import
com.intellij.psi.PsiReference
;
...
@@ -85,8 +86,18 @@ public class PyProtectedMemberInspection extends PyInspection {
...
@@ -85,8 +86,18 @@ public class PyProtectedMemberInspection extends PyInspection {
if
(!(
statement
instanceof
PyFromImportStatement
))
return
;
if
(!(
statement
instanceof
PyFromImportStatement
))
return
;
final
PyReferenceExpression
importReferenceExpression
=
node
.
getImportReferenceExpression
();
final
PyReferenceExpression
importReferenceExpression
=
node
.
getImportReferenceExpression
();
final
PyReferenceExpression
importSource
=
((
PyFromImportStatement
)
statement
).
getImportSource
();
final
PyReferenceExpression
importSource
=
((
PyFromImportStatement
)
statement
).
getImportSource
();
if
(
importReferenceExpression
!=
null
&&
importSource
!=
null
)
if
(
importReferenceExpression
!=
null
&&
importSource
!=
null
&&
!
isImportFromTheSamePackage
(
importSource
))
{
checkReference
(
importReferenceExpression
,
importSource
);
checkReference
(
importReferenceExpression
,
importSource
);
}
}
private
boolean
isImportFromTheSamePackage
(
PyReferenceExpression
importSource
)
{
PsiDirectory
directory
=
importSource
.
getContainingFile
().
getContainingDirectory
();
if
(
PyUtil
.
isPackage
(
directory
,
true
,
importSource
.
getContainingFile
())
&&
directory
.
getName
().
equals
(
importSource
.
getName
()))
{
return
true
;
}
return
false
;
}
}
@Override
@Override
...
...
This diff is collapsed.
Click to expand it.
python/testData/inspections/PyProtectedMemberInspection/importFromTheSamePackage/my_package/__init__.py
0 → 100644
+
0
-
0
View file @
d9b5e61d
This diff is collapsed.
Click to expand it.
python/testData/inspections/PyProtectedMemberInspection/importFromTheSamePackage/my_package/_package_internal_module.py
0 → 100644
+
2
-
0
View file @
d9b5e61d
def
very_smart_func
(
param
):
return
None
\ No newline at end of file
This diff is collapsed.
Click to expand it.
python/testData/inspections/PyProtectedMemberInspection/importFromTheSamePackage/my_package/my_public_module.py
0 → 100644
+
3
-
0
View file @
d9b5e61d
from
my_package
import
_package_internal_module
# False positive here
_package_internal_module
.
very_smart_func
(
"spam"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
python/testSrc/com/jetbrains/python/inspections/PyProtectedMemberInspectionTest.java
+
9
-
0
View file @
d9b5e61d
...
@@ -69,6 +69,15 @@ public class PyProtectedMemberInspectionTest extends PyTestCase {
...
@@ -69,6 +69,15 @@ public class PyProtectedMemberInspectionTest extends PyTestCase {
myFixture
.
checkHighlighting
(
false
,
false
,
true
);
myFixture
.
checkHighlighting
(
false
,
false
,
true
);
}
}
//PY-14234
public
void
testImportFromTheSamePackage
()
{
String
path
=
getTestName
(
true
);
myFixture
.
copyDirectoryToProject
(
path
+
"/my_package"
,
"./my_package"
);
myFixture
.
configureByFile
(
"/my_package/my_public_module.py"
);
myFixture
.
enableInspections
(
PyProtectedMemberInspection
.
class
);
myFixture
.
checkHighlighting
(
false
,
false
,
true
);
}
public
void
testModule
()
{
public
void
testModule
()
{
myFixture
.
configureByFiles
(
getTestName
(
true
)
+
".py"
,
"tmp.py"
);
myFixture
.
configureByFiles
(
getTestName
(
true
)
+
".py"
,
"tmp.py"
);
myFixture
.
enableInspections
(
PyProtectedMemberInspection
.
class
);
myFixture
.
enableInspections
(
PyProtectedMemberInspection
.
class
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment