# Clarifying the float/int/complex special case

**URL:** <https://discuss.python.org/t/clarifying-the-float-int-complex-special-case/54018>\
**Category:** Typing\
**Tags:** typing-spec\
**Created:** [May 23, 2024, 5:28am UTC](https://discuss.python.org/t/clarifying-the-float-int-complex-special-case/54018 "2024-05-23T05:28:48Z")\
**Posts on this page:** 1\
**Showing post:** 44

<div class="post-metadata">

**Author:** ![oscarbenjamin](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/oscarbenjamin/32/1209_2.png) [@oscarbenjamin](https://discuss.python.org/u/oscarbenjamin)\
**Post date:** [June 29, 2025, 9:21pm UTC](https://discuss.python.org/t/clarifying-the-float-int-complex-special-case/54018/44 "2025-06-29T21:21:15Z")

</div>

> [@jamesdow21](#):
>
> Anything that needs _specifically_ a float (and not an int) already can’t be annotated and that doesn’t change regardless of the outcome of this proposal. If anything this proposal makes those cases slightly easier because now the spec explicitly states what the `isinstance(x, float)` narrowing behavior should be

I’m not sure that it does make things easier. Currently mypy accepts this:

```python
from typing import overload

class Int: ...
class Float: ...

@overload
def convert(x: int) -> Int: ...
@overload
def convert(x: float) -> Float: ...
# def convert(x: float | int) -> Float: ...

def convert(x: int | float) -> Int | Float:
    if isinstance(x, int):
        return Int()
    elif isinstance(x, float):
        return Float()
    else:
        raise TypeError

```

If you switch the commented overload line so that `float` becomes `float | int` then mypy will reject this:

```python
$ mypy t.py
t.py:7: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]
Found 1 error in 1 file (checked 1 source file)

```

It is complaining because Float and Int are not related classes but float and int are also unrelated classes.

---

_[View the full topic](https://discuss.python.org/t/clarifying-the-float-int-complex-special-case/54018)._
