Skip to content

Comment on Reasons to use protocol buffers instead of JSONparent

Comments

Python doesn't have enumerations, per se. Here's how I'd represent that:

    if 'edit' in structure['access']:
         # can edit
    
In which case it really doesn't matter if there's junk in access. If I really felt the need to validate the structure, I could do so with:
    if not set(structure['access']).issubset(all_access_privs):
        raise ValueError('invalid access types passed in')
but more realistically, I'd rely on the ORM object to validate against the authoritative source - the database - and key off the errors there.

Python 3.4 has enums, if that's what you meant: https://docs.python.org/3/library/enum.html

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.