vmorkovyn / trafaret_validator Goto Github PK
View Code? Open in Web Editor NEWtrafaret_validator
License: MIT License
trafaret_validator
License: MIT License
Hi!
Recently I've found out that the library currently is not compatible with Python 2.7, but in setup.py it is marked it is supported... I'm currently working with Python 2 and unfortunately can't move to newer versions at the moment.
May I add python2 support to project, or you were going to remove it's support?
According to code in the library, there is possibility to change validators after it's instantiation... Which breaks logic of library, and produces bugs. However, logic in the code does not work at all (at least with Python 2, haven't tested behavior in Python 3 yet), because we can change validators only at instance level, what causes to validator break down completely. After such "mutation" it becomes fully unusable, so it is a bug.
My proposal is to remove possibility to change validator after it's creation, and replace it with possibility to mutate data passed to class using this api. In my opinion, the declarative way to implement validator means that you are not able to change it afterwards, and sometimes there should be possibility to change data after validation (it will smell not good, but at least have a bit of sense, unlike current implementation) ๐.
Example of usage should be like this:
class GreatValidator(TrafaretValidator):
id = t.Int()
name = t.String(allow_empty=False)
...
vld = GreatValidator(**json.loads(request.data)) # request.data = '{"id": 1}'
if not vld.validate():
if 'name' in vld.errors:
vld.name = 'Anonymous'
if vld.validate():
abort(412)
author = Author(id=vld.id, name=vld.name) # <Author id=1 name="Anonymous">
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.