Type Hierarchy and Object Model¶
Universal Base Type¶
The object type (mapping to System.Object) is the universal base type for all Sharpy types. All primitives (int, str, bool, etc.) and all Sharpy-defined types are assignable to object:
# object accepts any value
x: object = 42
x = "hello"
x = [1, 2, 3]
x = MyClass()
# Useful for heterogeneous collections
items: list[object] = [1, "hello", True, SomeClass()]
# Function accepting any type
def process(value: object) -> str:
return str(value)
Type Hierarchy¶
objectin type annotations maps toSystem.Object- Primitives (
int,str,bool, etc.) are assignable toobjectvia boxing - Structs are assignable to
objectvia boxing Noneis assignable toobject?but not toobject
Implementation
- 🔄 Lowered - object type annotations map to System.Object.