CKTIS / Python
Type system
Every object has a type that determines its operations, while a parameter annotation imposes no automatic runtime type check.
Version: Python 3.14; repository image, production runtime not attested
Syntax
type(value)
isinstance(value, Base)
len(value)Every object has a type that determines its operations, while a parameter annotation imposes no automatic runtime type check.
type(x) reports the concrete type and isinstance also recognizes subclasses. len uses the __len__ protocol, so an unrelated class can support it without inheriting from list.
Shelf returns length 3. True is an int instance with concrete type bool. Passing 12 raises TypeError at len.
class Sized:
def __len__(self): return 2
assert len(Sized())==2 and not isinstance(Sized,list)
assert type(True) is bool and issubclass(bool,int)
class Invalid:
def __len__(self): return -1
try: len(Invalid())
except ValueError: pass
else: raise AssertionError
Examples
class Shelf:
def __len__(self):
return 3
def size(value: list) -> int:
return len(value)
print(size(Shelf()), isinstance(True, int), type(True) is int)
try:
size(12)
except TypeError as error:
print(type(error).__name__)
Result
3 True False TypeError
Shelf returns length 3. True is an int instance with concrete type bool. Passing 12 raises TypeError at len.