diff --git a/CHANGES b/CHANGES
index af0d33172..301c10f2c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -26,6 +26,7 @@ Fixed:
- Expected `collections.iterable` but got `output:` false positive (see #317)
- Expected type `Iterable` (..), git `input: ` instead (see #319)
- Expected type `Iterable` (..), git `input: ` instead (see #320)
+- Workaround for: 'Shadows built-in name `input`' inspection on lambda parameters (see #133)
Version 0.8.0 build #0.8.0.214
-------------
diff --git a/src/main/kotlin/com/jetbrains/snakecharm/inspections/SmkIgnorePyInspectionExtension.kt b/src/main/kotlin/com/jetbrains/snakecharm/inspections/SmkIgnorePyInspectionExtension.kt
index 7caf9162a..677826683 100644
--- a/src/main/kotlin/com/jetbrains/snakecharm/inspections/SmkIgnorePyInspectionExtension.kt
+++ b/src/main/kotlin/com/jetbrains/snakecharm/inspections/SmkIgnorePyInspectionExtension.kt
@@ -1,8 +1,10 @@
package com.jetbrains.snakecharm.inspections
+import com.intellij.psi.PsiElement
import com.jetbrains.python.inspections.PyInspectionExtension
import com.jetbrains.python.psi.types.PyType
import com.jetbrains.python.psi.types.TypeEvalContext
+import com.jetbrains.snakecharm.lang.psi.SmkRuleOrCheckpointArgsSection
import com.jetbrains.snakecharm.lang.psi.types.SmkAvailableForSubscriptionType
class SmkIgnorePyInspectionExtension: PyInspectionExtension() {
@@ -13,7 +15,8 @@ class SmkIgnorePyInspectionExtension: PyInspectionExtension() {
return false
}
- // ignoreShadowed
+ override fun ignoreShadowed(element: PsiElement) = element is SmkRuleOrCheckpointArgsSection
+
// ignoreMissingDocstring
// ignoreMethodParameters
// getFunctionParametersFromUsage
diff --git a/src/main/kotlin/com/jetbrains/snakecharm/lang/highlighter/SnakemakeVisitorFilter.kt b/src/main/kotlin/com/jetbrains/snakecharm/lang/highlighter/SnakemakeVisitorFilter.kt
index 3a16eb827..fc9083784 100644
--- a/src/main/kotlin/com/jetbrains/snakecharm/lang/highlighter/SnakemakeVisitorFilter.kt
+++ b/src/main/kotlin/com/jetbrains/snakecharm/lang/highlighter/SnakemakeVisitorFilter.kt
@@ -1,20 +1,23 @@
package com.jetbrains.snakecharm.lang.highlighter
import com.intellij.psi.PsiFile
+import com.jetbrains.python.inspections.PyShadowingBuiltinsInspection
import com.jetbrains.python.inspections.PyUnboundLocalVariableInspection
import com.jetbrains.python.inspections.PyUnreachableCodeInspection
-import com.jetbrains.python.psi.PythonVisitorFilter
import com.jetbrains.python.psi.PyElementVisitor
+import com.jetbrains.python.psi.PythonVisitorFilter
import com.jetbrains.python.validation.ReturnAnnotator
-class SnakemakeVisitorFilter: PythonVisitorFilter {
+class SnakemakeVisitorFilter : PythonVisitorFilter {
private val unsupportedClasses = listOf(
- /** Instead use [com.jetbrains.snakecharm.lang.validation.SmkReturnAnnotator] **/
- ReturnAnnotator::class.java,
- // [HACK] See https://github.com/JetBrains-Research/snakecharm/issues/14
- PyUnreachableCodeInspection::class.java,
- // TODO: Need API for: PyResolveUtil.allowForwardReferences(node)
- PyUnboundLocalVariableInspection::class.java
+ /** Instead use [com.jetbrains.snakecharm.lang.validation.SmkReturnAnnotator] **/
+ ReturnAnnotator::class.java,
+ // [HACK] See https://github.com/JetBrains-Research/snakecharm/issues/14
+ PyUnreachableCodeInspection::class.java,
+ // TODO: Need API for: PyResolveUtil.allowForwardReferences(node)
+ PyUnboundLocalVariableInspection::class.java,
+ // See https://github.com/JetBrains-Research/snakecharm/issues/133, API required
+ PyShadowingBuiltinsInspection::class.java
// other possible candidates to disable
// //inspections
diff --git a/src/test/resources/features/highlighting/inspections/py_shadowing_builtins.feature b/src/test/resources/features/highlighting/inspections/py_shadowing_builtins.feature
new file mode 100644
index 000000000..36a1c59b5
--- /dev/null
+++ b/src/test/resources/features/highlighting/inspections/py_shadowing_builtins.feature
@@ -0,0 +1,33 @@
+Feature: Fixes PyShadowingBuiltinsInspection related false positives
+ Issue #133
+
+ @ignore("Is disabled dut to a workaround for #133")
+ Scenario: PyShadowingBuiltinsInspection works in snakemake files
+ Given a snakemake project
+ Given I open a file "foo.smk" with text
+ """
+ input = 1
+ """
+ And PyShadowingBuiltinsInspection inspection is enabled
+ Then I expect inspection weak warning on with message
+ """
+ Shadows built-in name 'input'
+ """
+ When I check highlighting weak warnings
+
+ Scenario Outline: Lambda params do not shadow builtin names
+ Given a snakemake project
+ Given I open a file "foo.smk" with text
+ """
+ rule_133:
+ input: "in"
+ params:
+ methylomes2=lambda wildcards, input: "",
+ """
+ And PyShadowingBuiltinsInspection inspection is enabled
+ Then I expect no inspection weak warnings
+ When I check highlighting weak warnings
+ Examples:
+ | rule_like |
+ | rule |
+ | checkpoint |
\ No newline at end of file
diff --git a/src/test/resources/features/highlighting/inspections/py_shadowing_names.feature b/src/test/resources/features/highlighting/inspections/py_shadowing_names.feature
new file mode 100644
index 000000000..153f0d7b3
--- /dev/null
+++ b/src/test/resources/features/highlighting/inspections/py_shadowing_names.feature
@@ -0,0 +1,50 @@
+Feature: Fixes PyShadowingNamesInspection related false positives
+ Issue #133
+
+ Scenario: PyShadowingNamesInspection works in snakemake files
+ Given a snakemake project
+ Given I open a file "foo.smk" with text
+ """
+ resources = 1
+ wd = 1
+ rule rule_133:
+ input: "in"
+ output: "out.txt"
+ threads: 5
+ params:
+ methylomes3=lambda wd, resources: "",
+ """
+ And PyShadowingNamesInspection inspection is enabled
+ # warning only for resources and wd because they == 1, not for input, output, threads
+ Then I expect inspection weak warning on in with message
+ """
+ Shadows name 'wd' from outer scope
+ """
+ Then I expect inspection weak warning on in with message
+ """
+ Shadows name 'resources' from outer scope
+ """
+
+ When I check highlighting weak warnings
+
+ Scenario Outline: Lambda params do not shadow section names
+ Given a snakemake project
+ Given I open a file "foo.smk" with text
+ """
+ rule_133:
+ input: "in"
+ output: "out.txt"
+ threads: 5
+ params:
+ methylomes1=lambda wildcards, output: "",
+ methylomes2=lambda wildcards, input: "",
+ methylomes3=lambda wildcards, resources: "",
+ methylomes4=lambda wildcards, threads: ""
+ """
+ And PyShadowingNamesInspection inspection is enabled
+ Then I expect no inspection weak warnings
+ When I check highlighting weak warnings
+ Examples:
+ | rule_like |
+ | rule |
+ | checkpoint |
\ No newline at end of file