{"action":"created","issue":{"url":"https://api.github.com/repos/jplana/python-etcd/issues/170","repository_url":"https://api.github.com/repos/jplana/python-etcd","labels_url":"https://api.github.com/repos/jplana/python-etcd/issues/170/labels{/name}","comments_url":"https://api.github.com/repos/jplana/python-etcd/issues/170/comments","events_url":"https://api.github.com/repos/jplana/python-etcd/issues/170/events","html_url":"https://github.com/jplana/python-etcd/issues/170","id":151572300,"number":170,"title":"Using a Lock as a context manager leads to AttributeError","user":{"login":"Konfuzzyus","id":1231074,"avatar_url":"https://avatars.githubusercontent.com/u/1231074?v=3","gravatar_id":"","url":"https://api.github.com/users/Konfuzzyus","html_url":"https://github.com/Konfuzzyus","followers_url":"https://api.github.com/users/Konfuzzyus/followers","following_url":"https://api.github.com/users/Konfuzzyus/following{/other_user}","gists_url":"https://api.github.com/users/Konfuzzyus/gists{/gist_id}","starred_url":"https://api.github.com/users/Konfuzzyus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Konfuzzyus/subscriptions","organizations_url":"https://api.github.com/users/Konfuzzyus/orgs","repos_url":"https://api.github.com/users/Konfuzzyus/repos","events_url":"https://api.github.com/users/Konfuzzyus/events{/privacy}","received_events_url":"https://api.github.com/users/Konfuzzyus/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-04-28T07:55:23Z","updated_at":"2016-12-23T12:28:36Z","closed_at":null,"body":"According to the documentation at http://python-etcd.readthedocs.io/en/latest/, the following code should be valid usage of the Lock class:\n\n```\nclient = etcd.Client()\nwith etcd.Lock(client, 'customer1') as my_lock:\n    do_stuff()\n    my_lock.is_acquired()  # True\n    my_lock.acquire(lock_ttl = 60)\nmy_lock.is_acquired() # False\n```\n\nThis throws an AttributeError at my_lock.is_acquired(), because my_lock is None at that point.    \n\nThe reason is the implementation of **enter** and **exit** on Lock, which do not comply with the context manager contract, see https://docs.python.org/2/reference/datamodel.html#context-managers.\n\ne.g.\n\n```\ndef __enter__(self):\n        \"\"\"\n        You can use the lock as a contextmanager\n        \"\"\"\n        self.acquire(blocking=True, lock_ttl=0)\n        # missing return self\n\n    def __exit__(self, type, value, traceback):\n        self.release()\n        # missing return False\n```\n"},"comment":{"url":"https://api.github.com/repos/jplana/python-etcd/issues/comments/268983095","html_url":"https://github.com/jplana/python-etcd/issues/170#issuecomment-268983095","issue_url":"https://api.github.com/repos/jplana/python-etcd/issues/170","id":268983095,"user":{"login":"Oloremo","id":4280480,"avatar_url":"https://avatars.githubusercontent.com/u/4280480?v=3","gravatar_id":"","url":"https://api.github.com/users/Oloremo","html_url":"https://github.com/Oloremo","followers_url":"https://api.github.com/users/Oloremo/followers","following_url":"https://api.github.com/users/Oloremo/following{/other_user}","gists_url":"https://api.github.com/users/Oloremo/gists{/gist_id}","starred_url":"https://api.github.com/users/Oloremo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Oloremo/subscriptions","organizations_url":"https://api.github.com/users/Oloremo/orgs","repos_url":"https://api.github.com/users/Oloremo/repos","events_url":"https://api.github.com/users/Oloremo/events{/privacy}","received_events_url":"https://api.github.com/users/Oloremo/received_events","type":"User","site_admin":false},"created_at":"2016-12-23T12:28:36Z","updated_at":"2016-12-23T12:28:36Z","body":"Is it a time to fork?"}}
{"actor":{"display_login":"Oloremo"}}