-
Notifications
You must be signed in to change notification settings - Fork 124
TryteString.as_string
needs some re-branding
#90
Comments
My recommendation is to call it
|
TryteString.as_string
needs a makeoverTryteString.as_string
needs some re-branding
Conclusion+1 for rename For what I think TryteString should act like this: >>> import iota
>>> ts = iota.codecs.encode(b'EXAMPLE'.decode('ascii'), 'utf-8') # Return TryteString
>>> ts = iota.codecs.encode('EXAMPLE', 'utf-8') # Return TryteString
>>> ts = iota.TryteString.from_string('EXAMPLE')
>>> ts = iota.TryteString.from_bytes(b'*\x15d\x96\xb5\x121\x8b\x01')
>>> ts = iota.TryteString('OBGCKBWBZBVBOB')
iota.TryteString('OBGCKBWBZBVBOB')
>>> ts.encode() # encode "tryte-string" to "tryte-in-bytes"
b'*\x15d\x96\xb5\x121\x8b\x01'
>>> ts.decode('utf-8') # decode "tryte-string" to "str"
>>> ts.decode() # default with utf-8
'EXAMPLE'
>>> str(ts)
'OBGCKBWBZBVBOB'
>>> bytes(ts) # Not b'OBGCKBWBZBVBOB'
b'*\x15d\x96\xb5\x121\x8b\x01' ExplainUsers are confused between
The point is, There isn't involve any decode/encode. So, But,
The deeper problem here comes from For what I think, we just mess up two different converts in one type. we want to do something like
BTW, @todofixthis you are using Python 2, right? In Python 3, |
These are great ideas, thanks @mlouielu ! tl;dr version: Overall, I think we're in agreement; I just have a couple of minor changes to request:
Changes to be made:
Everything else can stay the way it is — we'll make additional changes for #62, but for #90, I think we only need to rename a couple of methods. Let's tackle this one item at a time: 1.
|
- `TryteString.from_string` is now `from_unicode`. - `TryteString.as_string` is now `decode`. - `TryteString.as_bytes` is now `encode`. - Original methods are still available, but deprecated.
Summary of changes:
|
Scheduled for release: 2.0.4 |
- `TryteString.from_string` is now `from_unicode`. - `TryteString.as_string` is now `decode`. - `TryteString.as_bytes` is now `encode`. - Original methods are still available, but deprecated.
The
TryteString.as_string
desperately needs to be renamed; a lot of users are confusing it with__str__
.The text was updated successfully, but these errors were encountered: