-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check usages of
@PythonName
and @PythonCall
on overriding m…
…ethods (#1100) ### Summary of Changes Add some checks: * Must not override method with `@PythonCall` annotation * Overriding method must not have `@PythonCall` annotation * Python name of overriding method must equal the python name of the overridden method
- Loading branch information
1 parent
4fe4daa
commit 3021166
Showing
8 changed files
with
256 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...s/validation/inheritance/must not override method with python call annotation/main.sdsdev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package tests.validation.inheritance.mustNotOverrideMethodWithPythonCallAnnotation | ||
|
||
class MyClass1 { | ||
attr myAttribute: Int | ||
|
||
// $TEST$ no error "Cannot override a method that calls the '@PythonCall' annotation." | ||
@Pure | ||
@PythonCall("some_other_function") | ||
fun »withPythonCall«() | ||
|
||
// $TEST$ no error "Cannot override a method that calls the '@PythonCall' annotation." | ||
@Pure | ||
fun »withoutPythonCall«() | ||
} | ||
|
||
class MyClass2 sub MyClass1 { | ||
// $TEST$ no error "Cannot override a method that calls the '@PythonCall' annotation." | ||
@Pure | ||
@PythonCall("some_other_function") | ||
fun »withPythonCall«() | ||
|
||
// $TEST$ no error "Cannot override a method that calls the '@PythonCall' annotation." | ||
@Pure | ||
@PythonCall("some_other_function") | ||
fun »withoutPythonCall«() | ||
} | ||
|
||
class MyClass3 sub MyClass1 { | ||
// $TEST$ no error "Cannot override a method that calls the '@PythonCall' annotation." | ||
@Pure | ||
fun »myAttribute«() | ||
|
||
// $TEST$ error "Cannot override a method that calls the '@PythonCall' annotation." | ||
@Pure | ||
fun »withPythonCall«() | ||
} |
24 changes: 24 additions & 0 deletions
24
...validation/inheritance/overriding method must not have python call annotation/main.sdsdev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package tests.validation.inheritance.overridingMethodMustNotHavePythonCallAnnotation | ||
|
||
class MyClass1 { | ||
// $TEST$ no error "An overriding method must not call the '@PythonCall' annotation." | ||
@Pure | ||
@PythonCall("some_other_function") | ||
fun »withPythonCall«() | ||
|
||
// $TEST$ no error "An overriding method must not call the '@PythonCall' annotation." | ||
@Pure | ||
fun »withoutPythonCall«() | ||
} | ||
|
||
class MyClass2 sub MyClass1 { | ||
// $TEST$ error "An overriding method must not call the '@PythonCall' annotation." | ||
@Pure | ||
@PythonCall("some_other_function") | ||
fun »withPythonCall«() | ||
|
||
// $TEST$ error "An overriding method must not call the '@PythonCall' annotation." | ||
@Pure | ||
@PythonCall("some_other_function") | ||
fun »withoutPythonCall«() | ||
} |
13 changes: 13 additions & 0 deletions
13
...nheritance/overriding method should differ from overridden method/with python call.sdsdev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package tests.validation.inheritance.overridingMethodShouldDifferFromOverriddenMethod.withPythonCall | ||
|
||
class MyClass1 { | ||
@Pure | ||
fun f() | ||
} | ||
|
||
class MyClass2 { | ||
// $TEST$ no info "Overriding member is identical to overridden member and can be removed." | ||
@Pure | ||
@PythonCall("") | ||
fun »f«() | ||
} |
34 changes: 34 additions & 0 deletions
34
...nheritance/overriding method should differ from overridden method/with python name.sdsdev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package tests.validation.inheritance.overridingMethodShouldDifferFromOverriddenMethod.withPythonName | ||
|
||
class MyClass1 { | ||
@Pure | ||
fun myFunction1() | ||
|
||
@Pure | ||
@PythonName("my_function_2") | ||
fun myFunction2() | ||
} | ||
|
||
class MyClass2 sub MyClass1 { | ||
// $TEST$ info "Overriding member is identical to overridden member and can be removed." | ||
@Pure | ||
@PythonName("myFunction1") | ||
fun »myFunction1«() | ||
|
||
// $TEST$ info "Overriding member is identical to overridden member and can be removed." | ||
@Pure | ||
@PythonName("my_function_2") | ||
fun »myFunction2«() | ||
} | ||
|
||
class MyClass3 sub MyClass1 { | ||
// $TEST$ no info "Overriding member is identical to overridden member and can be removed." | ||
@Pure | ||
@PythonName("anotherFunction1") | ||
fun »myFunction1«() | ||
|
||
// $TEST$ no info "Overriding member is identical to overridden member and can be removed." | ||
@Pure | ||
@PythonName("anotherFunction2") | ||
fun »myFunction2«() | ||
} |
59 changes: 59 additions & 0 deletions
59
...sts/resources/validation/inheritance/python name must match overridden method/main.sdsdev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package tests.validation.inheritance.pythonNameMustMatchOverriddenMethod | ||
|
||
class MyClass1 { | ||
// $TEST$ no error "The Python name must match the overridden member." | ||
attr »myAttribute1«: Int | ||
|
||
// $TEST$ no error "The Python name must match the overridden member." | ||
@PythonName("my_Attribute_2") | ||
attr »myAttribute2«: Int | ||
|
||
// $TEST$ no error "The Python name must match the overridden member." | ||
@Pure | ||
fun »myFunction1«() | ||
|
||
// $TEST$ no error "The Python name must match the overridden member." | ||
@Pure | ||
@PythonName("my_function_2") | ||
fun »myFunction2«() | ||
} | ||
|
||
class MyClass2 sub MyClass1 { | ||
// $TEST$ no error "The Python name must match the overridden member." | ||
@PythonName("myAttribute1") | ||
attr »myAttribute1«: Int | ||
|
||
// $TEST$ no error "The Python name must match the overridden member." | ||
@PythonName("my_Attribute_2") | ||
attr »myAttribute2«: Int | ||
|
||
// $TEST$ no error "The Python name must match the overridden member." | ||
@Pure | ||
@PythonName("myFunction1") | ||
fun »myFunction1«() | ||
|
||
// $TEST$ no error "The Python name must match the overridden member." | ||
@Pure | ||
@PythonName("my_function_2") | ||
fun »myFunction2«() | ||
} | ||
|
||
class MyClass3 sub MyClass1 { | ||
// $TEST$ error "The Python name must match the overridden member." | ||
@PythonName("anotherAttribute1") | ||
attr »myAttribute1«: Int | ||
|
||
// $TEST$ error "The Python name must match the overridden member." | ||
@PythonName("another_attribute_2") | ||
attr »myAttribute2«: Int | ||
|
||
// $TEST$ error "The Python name must match the overridden member." | ||
@Pure | ||
@PythonName("anotherFunction1") | ||
fun »myFunction1«() | ||
|
||
// $TEST$ error "The Python name must match the overridden member." | ||
@Pure | ||
@PythonName("anotherFunction2") | ||
fun »myFunction2«() | ||
} |