Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

TryteString.random() should use cls.LEN as its default length, when available #166

Closed
todofixthis opened this issue Mar 7, 2018 · 3 comments

Comments

@todofixthis
Copy link
Contributor

When calling a class' random() method, the length parameter should only be required if the class has no LEN attribute.

Example:

>>> from iota import Address
>>> Address.random()

# Expected Result
Address(b'... 81 random trytes ...')

# Actual Result
TypeError: random() missing 1 required positional argument: 'length'
@todofixthis todofixthis changed the title TryteString.random() should use self.LEN as its default length TryteString.random() should use cls.LEN as its default length, when available Mar 7, 2018
@marko-k0
Copy link

Does this mean that every class that is a subclass of TryteString and has LEN class attribute needs to override random class method:

    @classmethod
    def random(cls, length=LEN):
        return super(Address, cls).random(length)

Is more elegant solution possible - changes only in the TryteString class?

@todofixthis
Copy link
Contributor Author

Hey @redondo-mk it should automatically use cls.LEN when length is None; see https://github.com/iotaledger/iota.lib.py/pull/167/files#diff-d6aa393b4abd731eaf02e44ac1dc7d5aR64

@xie4991
Copy link

xie4991 commented Nov 28, 2018

You can try this:Address.random().choice(81 random trytes )
It may be solved by giving a limited range later.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants