EJTP-lib-python icon indicating copy to clipboard operation
EJTP-lib-python copied to clipboard

Make addresses a class instead of a list ($50)

Open MoritzS opened this issue 12 years ago • 3 comments

We should make a address class, that should have the methods that currently are in ejtp.address. If it is a desired functionality, the address class could still implement the __getitem__ method so that code that assumes the address is a list will still work.

I see following advantages with doing that:

  • for converting and creating addresses you will just use methods instead of (in my opinion) ugly auxiliary methods
  • addresses themselves will be more descriptive, so a programmer will better understand how the address works while reading the source code

MoritzS avatar Jun 08 '13 15:06 MoritzS

I'm inclined to agree. This seems like a perfect fit for named tuples, if it's supported in all our Python versions. If not, we can just go manual. We also have to consider serialization - I'll check later if JSON can nicely serialize arbitrary objects that provide the iteration interface.

On Sat, Jun 8, 2013 at 8:47 AM, Moritz Sichert [email protected]:

We should make a address class, that should have the methods that currently are in ejtp.address. If it is a desired functionality, the address class could still implement the getitem method so that code that assumes the address is a list will still work.

I see following advantages with doing that:

  • for converting and creating addresses you will just use methods instead of (in my opinion) ugly auxiliary methods
  • addresses themselves will be more descriptive, so a programmer will better understand how the address works while reading the source code

— Reply to this email directly or view it on GitHubhttps://github.com/campadrenalin/EJTP-lib-python/issues/137 .

MaddieM4 avatar Jun 08 '13 17:06 MaddieM4

Looks like the JSON module is compatible with namedtuples, but not arbitrary iterables. And namedtuples can be subclassed if we want anything special. All of which is supported in Python 2.6+. So this is definitely the way forward, IMHO.

http://docs.python.org/dev/library/collections.html#collections.namedtuple

MaddieM4 avatar Jun 08 '13 20:06 MaddieM4

Bounty is $50.

http://www.freedomsponsors.org/core/issue/275/make-addresses-a-class-instead-of-a-list


(Copied from acceptance criteria)

Create a namedtuple subclass for EJTP addresses, overriding the init function such that passing in a single string as an argument will automatically JSON decode the string and use that for initialization arguments. Then replace every usage of list addresses with the new Address class, wherever the replacement isn't totally insane. If you're not sure, ask in a Github comment, discussion is fun.

MaddieM4 avatar Jun 08 '13 20:06 MaddieM4