Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: Validation in Python (was: raise None) Date: Thu, 31 Dec 2015 11:26:14 +1100 Lines: 29 Message-ID: References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de Lgo4pj00jN4dpxapTpCcmg2MFGQkGFPlj+efSrY5k4Ew== Cancel-Lock: sha1:gn1CCyognOYKAS6SSX6uJVrZmkQ= Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'url:pypi': 0.03; 'messages.': 0.04; 'subject:Python': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:None': 0.09; 'python': 0.10; 'argument': 0.15; 'json,': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'simplicity.': 0.16; 'language': 0.19; 'library': 0.20; 'seems': 0.23; 'tried': 0.24; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'error': 0.27; 'checking': 0.27; 'question': 0.27; 'time:': 0.27; 'code': 0.30; 'useful': 0.33; 'url:python': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'library.': 0.35; 'primarily': 0.35; 'url:org': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'data': 0.39; 'to:addr:python.org': 0.40; 'provide': 0.61; 'our': 0.64; 'developed': 0.66; 'repeat': 0.67; 'skip:\xe2 10': 0.70; 'yourself': 0.73; '_o__)': 0.84; 'received:125': 0.84; 'subject:Validation': 0.84; 'ask,': 0.91; 'belief': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101030 Steven D'Aprano writes: > I have a lot of functions that perform the same argument checking each > time: Not an answer to the question you ask, but: Have you tried the data validation library “voluptuous”? Voluptuous, despite the name, is a Python data validation library. It is primarily intended for validating data coming into Python as JSON, YAML, etc. It has three goals: Simplicity. Support for complex data structures. Provide useful error messages. Seems like a good way to follow Don't Repeat Yourself in code that needs a lot of validation of inputs. -- \ “It's my belief we developed language because of our deep inner | `\ need to complain.” —Jane Wagner, via Lily Tomlin | _o__) | Ben Finney