sixty-north / cosmic-ray

Mutation testing for Python
MIT License
565 stars 57 forks source link

Don't mutate boolean operator inside type annotations #465

Closed Alcolo47 closed 5 years ago

Alcolo47 commented 5 years ago

Don't mutate type annotation: ('or' on: a: int or float = 1) For this, I introduce ObjTest to test easily many conditions in parso tree.

abingham commented 5 years ago

This is interesting. It makes me wonder: should we just prevent all mutation of type annotations? The annotations are only intended for external tools and should have no effect on runtime behavior. In that sense, mutations to type annotations will always be equivalent mutants: impossible to detect. Does that sound right?

Alcolo47 commented 5 years ago

Yes, I think we don't have to mutate annotation because it will always create a mutant.

Today, annotation is used for typing, and is used by tools to detect type mismatches. But it is only convention, maybe some others use can be found.

To use them in application, annotations must be accessible by code, but without introspection, you can't. And to add information on variables, other ways already exist. I think in fact, that annotation handles and will handle only meta-information (like types) and never application information.

abingham commented 5 years ago

Ok, it sounds like we agree that we can disable all mutation in type annotations. If that's the case, then we should abandon this PR and consider how to best do that. I think a new issue is where we should start; we can discuss the implementation strategy there. Does that sound ok to you?

Alcolo47 commented 5 years ago

If you have a look on the new PR pragma filter with interceptors, we can see my proposition of a new interceptor class. With this new interceptor, we can easyly move annotation detection to a new interceptor. And we can enlarge this detection for other operators.

abingham commented 5 years ago

Excellent, thanks, I'll take a look at that!

we can easyly move annotation detection to a new interceptor.

I could be convinced to put this detection into the core of CR. If we make a blanket policy of never mutating annotations, then that's an appropriate place for it. That way we never mutated annotations in the workdb; they would all be skipped all of the time, so they'd be noise.

It sounds like we can close the PR. If you agree, please do so.

Alcolo47 commented 5 years ago

I close this PR because I made new PR https://github.com/sixty-north/cosmic-ray/pull/475 based on class base interceptor.