You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to represent records, variants, arrays, and other non-primitives in Python typing, how to represent all types (make an issue for each showing how they should look). I just found this awesome Rust/Python types chart: https://pyo3.rs/v0.13.2/conversions/tables.html
text
# str should be an alias to texttext=str
blob
blob=bytes# orblob=bytearray
nat and natN
nat=intnat64=intnat32=intnat16=intnat8=int
int and intN
# int is builtinint64=intint32=intint16=intint8=int
# kybra modulerecord=TypedDict# examplefromkybraimportrecordMyRecord=record('MyRecord', {
'prop1': str,
'prop2': int
})
# orclassMyRecord(record):
prop1: str,
prop2: int# or ideally I think we want this, behaving like a data class or TypedDict@recordclassMyRecord:
prop1: str,
prop2: int
tuple
my_tuple=tuple[str, str]
variant
# TODO consider what to do after figuring out records# TODO we might want to see what ic-py is doing# We might just want to do some weird inheritance thing with TypedDict, like Variant# We might want to do that for records and variants# kybra modulevariant=TypedDict# examplefromkybraimportvariantMyVariant=variant('MyVariant', {
'prop1': str,
'prop2': int
})
# orclassMyVariant(variant):
prop1: str,
prop2: int# or ideally I think we want this, behaving like a data class or TypedDict@variantclassMyVariant:
prop1: str,
prop2: int
fromic.principalimportPrincipalp=Principal() # default is management canister id `aaaaa-aa`p1=Principal(bytes=b'') # create an instance from bytesp2=Principal.anonymous() # create anonymous principalp3=Principal.self_authenticating(pubkey) # create a principal from public keyp4=Principal.from_str('aaaaa-aa') # create an instance from stringp5=Principal.from_hex('xxx') # create an instance from hex
For variant and record I'm beginning to think it isn't possible to design exactly what we want with Python's type system. So, I think we should consider just using TypedDict and/or decorators. For variants, the user will just have to deal with an optional type of some kind for each branch...maybe we can create a type called branch or arm or case that is null or a certain type...I guess opt could be that?
I think we might want to just do a Case similar to how they do it...variant will have cases, record will not. Now we need to figure out how to make these TypedDict...I think the getItem function might be key here
How to represent records, variants, arrays, and other non-primitives in Python typing, how to represent all types (make an issue for each showing how they should look). I just found this awesome Rust/Python types chart: https://pyo3.rs/v0.13.2/conversions/tables.html
text
blob
nat and natN
int and intN
float32
float64
bool
# bool is builtin
null
vec t
opt t
record
tuple
variant
func
service
principal
Use the
Principal
type from https://github.com/rocklabs-io/ic-pyreserved
empty
canister
The text was updated successfully, but these errors were encountered: