# Make \_\_replace\_\_ stop interfering with variance inference

**URL:** <https://discuss.python.org/t/make-replace-stop-interfering-with-variance-inference/96092>\
**Category:** Typing\
**Created:** [June 20, 2025, 1:43am UTC](https://discuss.python.org/t/make-replace-stop-interfering-with-variance-inference/96092 "2025-06-20T01:43:54Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![MegaIng](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/megaing/32/16162_2.png) [@MegaIng](https://discuss.python.org/u/MegaIng)\
**Post date:** [June 20, 2025, 6:28pm UTC](https://discuss.python.org/t/make-replace-stop-interfering-with-variance-inference/96092/16 "2025-06-20T18:28:36Z")

</div>

If type checker notice that covariance is an issue, they could point to the methods that cause this variance - especially if it’s a single synthesized method. I don’t know enough about type checker implementations to create a POC, but I would be surprised if this is information that is hard to get for them.

E.g. the pyright error message for the example in OP:

```python
Method "f" overrides class "X" in an incompatible manner
  Return type mismatch: base method returns type "C[object]", override returns type "C[float]"
    "C[float]" is not assignable to "C[object]"
      Type parameter "T@C" is invariant, but "float" is not the same as "object" (reportIncompatibleMethodOverride)

```

Could be extended to include

```python
"T@C" is invariant because of the synthesized " __replace__" method.

```

The inclusion or exclusion of this message could be controlled by heuristics and/or type checker options.

---

_[View the full topic](https://discuss.python.org/t/make-replace-stop-interfering-with-variance-inference/96092)._
