Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions hathor/nanocontracts/custom_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,6 @@ def filter(function: None | Callable[[T], object], iterable: Iterable[T]) -> Ite
# (i: SupportsNext[T], default: V, /) -> T | V
'next': builtins.next,

# O(1)
# type object
# () -> object
'object': builtins.object,

# O(1)
# (number: int | SupportsIndex, /) -> str
'oct': builtins.object,
Expand Down Expand Up @@ -586,25 +581,12 @@ def filter(function: None | Callable[[T], object], iterable: Iterable[T]) -> Ite
# (iterable: Iterable[T], /, start: T) -> T
'sum': builtins.sum,

# O(1)
# type super
# (t: Any, obj: Any, /) -> super
# (t: Any, /) -> super
# () -> super
'super': builtins.super,

# XXX: consumes an iterator when calling
# O(N) for N=len(iterable)
# type tuple(Sequence[T])
# (iterable: Iterable[T] = ..., /) -> tuple[T]
'tuple': builtins.tuple,

# O(1)
# type type
# (o: object, /) -> type
# (name: str, bases: tuple[type, ...], namespace: dict[str, Any], /, **kwds: Any) -> T(type)
'type': builtins.type,

# O(1)
# type zip(Iterator[T])
# (iter: Iterable[T], /, *, strict: bool = ...) -> zip[tuple[T]]
Expand Down Expand Up @@ -766,7 +748,7 @@ def filter(function: None | Callable[[T], object], iterable: Iterable[T]) -> Ite
# XXX: used to dynamically set attributes, must not be allowed
'setattr': _generate_disabled_builtin_func('setattr'),

# XXX: same reasoning as locals
# XXX: can be used to inspect an object's attributes, including "private" ones
'vars': _generate_disabled_builtin_func('vars'),

# XXX: disallow just in case
Expand All @@ -791,4 +773,25 @@ def filter(function: None | Callable[[T], object], iterable: Iterable[T]) -> Ite
# doc: str | None = ...,
# ) -> property
'property': _generate_disabled_builtin_func('property'),

# XXX: Can be used to get an object's class and its metaclass
# O(1)
# type type
# (o: object, /) -> type
# (name: str, bases: tuple[type, ...], namespace: dict[str, Any], /, **kwds: Any) -> T(type)
'type': _generate_disabled_builtin_func('type'),

# XXX: Root object which contains dangerous methods such as `__setattr__`
# O(1)
# type object
# () -> object
'object': _generate_disabled_builtin_func('object'),

# XXX: Can be used to get the root `object`
# O(1)
# type super
# (t: Any, obj: Any, /) -> super
# (t: Any, /) -> super
# () -> super
'super': _generate_disabled_builtin_func('super'),
}
3 changes: 3 additions & 0 deletions hathor/nanocontracts/on_chain_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
'open',
'setattr',
'vars',
'type',
'object',
'super',
}


Expand Down
4 changes: 4 additions & 0 deletions tests/nanocontracts/test_exposed_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
'memoryview.tobytes',
'memoryview.tolist',
'memoryview.toreadonly',
'object.some_new_attribute',
'open.some_new_attribute',
'print.some_new_attribute',
'property.deleter',
Expand All @@ -192,6 +193,9 @@
'range.stop',
'repr.some_new_attribute',
'setattr.some_new_attribute',
'super.some_new_attribute',
'type.mro',
'type.some_new_attribute',
'vars.some_new_attribute',
]

Expand Down