From 4a377bff6a76465df6f7e26e5f05b7ccd68f8c3e Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 13 Sep 2018 14:20:51 +0200 Subject: [PATCH] address @flub's remarks -- strike myattr and use imported attr directly --- python/src/deltachat/account.py | 26 +++++++++++--------- python/src/deltachat/{myattr.py => types.py} | 15 +---------- 2 files changed, 15 insertions(+), 26 deletions(-) rename python/src/deltachat/{myattr.py => types.py} (68%) diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 9ad033af..4799dc87 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -10,12 +10,14 @@ except ImportError: import deltachat from . import capi from .capi import ffi -from .myattr import attrib_CData, attrs, attrib_int, cached_property +from .types import cached_property +import attr +from attr import validators as v -@attrs +@attr.s class EventHandler(object): - dc_context = attrib_CData() + dc_context = attr.ib(validator=v.instance_of(ffi.CData)) def read_url(self, url): try: @@ -76,10 +78,10 @@ class EventLogger: tname, self.logid, evt_name, data1, data2)) -@attrs +@attr.s class Contact(object): - dc_context = attrib_CData() - id = attrib_int() + dc_context = attr.ib(validator=v.instance_of(ffi.CData)) + id = attr.ib(validator=v.instance_of(int)) @cached_property # only get it once because we only free it once def dc_contact_t(self): @@ -105,10 +107,10 @@ class Contact(object): return capi.lib.dc_contact_is_verified(self.dc_contact_t) -@attrs +@attr.s class Chat(object): - dc_context = attrib_CData() - id = attrib_int() + dc_context = attr.ib(validator=v.instance_of(ffi.CData)) + id = attr.ib(validator=v.instance_of(int)) @cached_property def dc_chat_t(self): @@ -125,10 +127,10 @@ class Chat(object): return Message(self.dc_context, msg_id) -@attrs +@attr.s class Message(object): - dc_context = attrib_CData() - id = attrib_int() + dc_context = attr.ib(validator=v.instance_of(ffi.CData)) + id = attr.ib(validator=v.instance_of(int)) @cached_property def dc_msg_t(self): diff --git a/python/src/deltachat/myattr.py b/python/src/deltachat/types.py similarity index 68% rename from python/src/deltachat/myattr.py rename to python/src/deltachat/types.py index ead414a7..3fe68c17 100644 --- a/python/src/deltachat/myattr.py +++ b/python/src/deltachat/types.py @@ -1,19 +1,6 @@ -from attr import attrs, attrib # noqa -from attr import validators as v - - -def attrib_int(): - return attrib(validator=v.instance_of(int)) - - -def attrib_CData(): - from deltachat.capi import ffi - return attrib(validator=v.instance_of(ffi.CData)) - - # copied over unmodified from # https://github.com/devpi/devpi/blob/master/common/devpi_common/types.py -# where it's also tested + def cached_property(f): """returns a cached property that is calculated by function f"""