Giter VIP home page Giter VIP logo

trafaret_validator's People

Contributors

cleac avatar vmorkovyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

trafaret_validator's Issues

Python 2 compatibility issue

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?

A question on logic of setting/getting attributes

Problem:

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.

Possible solution:

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">

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.