-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#86drtepaj - Verify if type annotation using the literal types instea… #1239
Conversation
…d of the typing aliases work in smart contracts
@@ -318,7 +318,7 @@ def properties(tokenId: bytes) -> Dict[Any, Any]: | |||
""" | |||
metaBytes = cast(str, get_meta(tokenId)) | |||
expect(len(metaBytes) != 0, 'No metadata available for token') | |||
metaObject = cast(Dict[str, str], json_deserialize(metaBytes)) | |||
metaObject = cast(dict[str, str], json_deserialize(metaBytes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cast
function from the typing
module does not support the native dict
type for casting. Please revert this change and continue using Dict
from the typing
module.
@@ -378,7 +378,7 @@ def internal_deploy(owner: UInt160): | |||
storage.put_bool(PAUSED, False) | |||
storage.put_int(TOKEN_COUNT, 0) | |||
|
|||
auth: List[UInt160] = [] | |||
auth: list[UInt160] = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type hint for the list auth
should be List[UInt160]
instead of list[UInt160]
. The List
type hint is more descriptive and provides better type checking than the generic list
type hint.
|
||
|
||
def Main(op: str, args: list) -> List[int]: | ||
def Main(op: str, args: list) -> list[int]: | ||
a = [1, 2, 3] | ||
list.append(a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The list.append()
method requires an element as an argument to append to the list. Please provide an argument.
|
||
|
||
def Main(op: str, args: list) -> List[int]: | ||
def Main(op: str, args: list) -> list[int]: | ||
a = [1, 2, 3] | ||
a.append(4, 5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The append
method should only take one argument. If you want to add multiple elements, consider using the extend
method or appending them one by one.
|
||
|
||
def Main(op: str, args: list) -> Tuple[int]: | ||
def Main(op: str, args: list) -> tuple[int]: | ||
a = (1, 2, 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Python, tuples are immutable and do not have an append
method. Please revise this to use a different data structure or modify the tuple in a way that doesn't involve appending.
|
||
|
||
def Main(a: Tuple[int, ...]) -> int: | ||
def Main(a: tuple[int, ...]) -> int: | ||
a[0] = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tuples in Python are immutable, so you cannot change their values after they are created. The line a[0] = 1
will raise a TypeError. Consider using a list if you need to change the values.
|
||
from boa3.builtin.compile_time import public | ||
|
||
|
||
@public | ||
def Main(value: Any) -> int: | ||
x = cast(Dict[str, int], value) | ||
x = cast(dict[str, int], value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dict
type does not support indexing in Python. Please use typing.Dict
for type hinting a dictionary.
from boa3.builtin.compile_time import public | ||
|
||
|
||
@public | ||
def Main(a: Tuple[int]): | ||
def Main(a: tuple[int]): | ||
b: str = a[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type of the variable a
is tuple[int]
which means it is a tuple of integers. However, you are trying to assign the first element of this tuple to a string variable b
. This will cause a type mismatch error. Please ensure the types are compatible.
|
||
|
||
def Main(a: Tuple[int]): | ||
def Main(a: tuple[int]): | ||
a[0] = '1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python's built-in tuple
type does not support type hinting for its elements. Please use typing.Tuple
for type hinting in function arguments.
from boa3.builtin.compile_time import public | ||
|
||
|
||
@public | ||
def Main(a: [int]) -> [int]: # should be List[int] instead of [int] | ||
def Main(a: [int]) -> [int]: # should be list[int] instead of [int] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type hinting for the parameter a
and the return type of the function Main
is incorrect. It should be list[int]
instead of [int]
. Please correct it.
Summary or solution description
Changed the usage of deprecated methods from
typing
, specificallyList
,Dict
andTuple
, to use the native implementations.Sequence
,Union
,Optional
andMapping
will be changed in different issues