Conversation

anyway just learned python typing invented a new kind of voldemort type -- one which when named doesn't actually name it

`float` and `int` are two distinct types in the type system

but if you write `x: float` that actually means `x: float | int`. but if you write `x: float | int` that means `x: float | int | int`.

anyway that's why `ty` has a `JustFloat` extension that is an actual alias for actual `float` that doesn't expand to `float | int`, so you can actual refer to... just float

https://play.ty.dev/a8714369-9b4c-4028-9418-26727b546205

4
4
1

`complex` is `complex | float | int`

:)

1
0
0

@Gankra i can see where they are coming with complex being complex | float but int isn’t even a float subset

0
0
2

@mindpersephone it naturally happens constantly in the typesystem, they've gotta deal with it anyway

0
0
0

@Gankra have you encountered the psychic damage that `bool` is a subtype of `int` for reasons?

2
0
0

@apmasell never heard of bool, my only friend is `Literal['False']`

0
0
0

@Gankra oh so it's a bit like subtypes? i guess with all of the implicit conversions that happen in python's arithmetic it kind of makes sense.

oh! maybe the reason was so you can pass an integer literal to a function expecting a float.

0
1
0

@apmasell @Gankra TIL that's not the type checker people making things hard, it's stated in the documentation of `bool`

1
0
0

@orman @apmasell @Gankra issubclass(bool, int) has been true for the entire time that bool has been a class; in fact, isinstance(True, int) and isinstance(False, int) has been true (or rather, 1) since before bool even existed!

in python 2.0 and 2.0.1, there was no bool in the global namespace, and True and False were just the ints 0 and 1 respectively. python 2.1 introduced bool as this function (defined in Lib/symtable.py):

def bool(x):
"""Helper to force boolean result to 1 or 0"""
if x:
return 1
return 0

only in python 2.3 did bool become its own class (defined in Objects/boolobject.c), and from that point onward bool has always subclassed int. type checkers treating bool as a subtype of int just reflects how python has worked since long before the type checkers existed.

(source: poking around source tarballs downloaded from https://www.python.org/ftp/python/)

0
1
0