Git Product home page Git Product logo

Comments (6)

kragniz avatar kragniz commented on July 22, 2024

You'd prefer something like this?

>>> import etcd3
>>> etcd = etcd3.client()
>>> etcd.get('not-a-key')
(None, <etcd3.client.KVMetadata object at 0x7f5e32621790>)
>>> etcd.get('not-a-key', default=b'toot')
(b'toot', <etcd3.client.KVMetadata object at 0x7f5e32621650>)

from python-etcd3.

yannlambret avatar yannlambret commented on July 22, 2024

I would indeed, I think it would allow to write more concise code in most situations. What do you think ?

from python-etcd3.

zimnx avatar zimnx commented on July 22, 2024

Official etcd2 client throws exception when key is not found, I would prefer current behavior. Current implementations can simply switch type of Exception handled without modifying logic around client.

from python-etcd3.

yannlambret avatar yannlambret commented on July 22, 2024

There is no official Python client for etcd, just third party libraries referenced in the documentation - as this one is. If you take a look at the behavior of the go etcd client for v3 API (which is the only one maintained by CoreOS as part of the project), it returns a data structure as part of the response (resp.Kvs) which is empty if a key is not found, and the error returned by the .Get method is 'nil' in this case.

from python-etcd3.

minus7 avatar minus7 commented on July 22, 2024

I'd mimic the behaviour of dict: raise KeyError (or a subclass thereof containing the KVMetadata object) if a non-existent key is accessed without providing a default. To check if a key exists in/__contains__ should be used. (A successful get returning a tuple isn't particularly nice either, maybe a proxy object would work there better?)

Disclaimer: I've never used etcd nor this library.

from python-etcd3.

kragniz avatar kragniz commented on July 22, 2024

Addressed by #73

from python-etcd3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.