Skip to content

Fix ground truth for inheritance/MRO benchmarks (Liskov substitution)#14

Open
jaltmayerpizzorno wants to merge 20 commits intosecure-software-engineering:mainfrom
plasma-umass:fix-inheritance-ground-truth
Open

Fix ground truth for inheritance/MRO benchmarks (Liskov substitution)#14
jaltmayerpizzorno wants to merge 20 commits intosecure-software-engineering:mainfrom
plasma-umass:fix-inheritance-ground-truth

Conversation

@jaltmayerpizzorno
Copy link
Contributor

Hi! Thanks again for creating and maintaining TypeEvalPy — it's been an invaluable resource for our work evaluating type inference tools.

While running the benchmarks, we noticed that 5 inheritance/MRO ground truth annotations use only each method body's return type, without accounting for the Liskov substitution principle. When annotated as given, mypy --strict reports incompatible override errors on all of them. Widening the parent method return types to include the subclass override types resolves this and makes the annotations consistent with what a type-safe program requires.

Affected benchmarks

Benchmark Function Before After
`classes/inheritance_overriding` `MyClass.func` `str` `int|str`
`mro/parents_same_superclass` `A.func` `str` `int|str`
`mro/self_assignment` `B.func` `int` `int|str`
`mro/two_parents` `B.func` `str` `int|str`
`mro/two_parents_method_defined` `A.func` `float` `float|str`
`mro/two_parents_method_defined` `B.func` `int` `float|int|str`

We verified with `mypy --strict` that the original annotations produce override errors and the corrected ones pass cleanly.

Thanks for considering this!

…meration;

- made test more interesting by substituting <value1> with more than just "int";
…able definition.

  Corresponds change a40d4db in the templates;
The previous ground truth annotated each method with only its body's
return type, ignoring that subclass overrides must have compatible
return types per the Liskov substitution principle. When annotated as
given, mypy --strict reports override errors on every affected
benchmark. The corrected annotations widen parent method return types
to include subclass override types, making all benchmarks pass mypy.

Affected benchmarks:
- classes/inheritance_overriding: MyClass.func str -> int|str
- mro/parents_same_superclass: A.func str -> int|str
- mro/self_assignment: B.func int -> int|str
- mro/two_parents: B.func str -> int|str
- mro/two_parents_method_defined: A.func float -> float|str,
  B.func int -> float|int|str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant