V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
huntzhan
V2EX  ›  Python

个人项目, magic-parameter, 传入参数类型检查

  •  
  •   huntzhan ·
    huntzhan · 2016-04-18 01:37:14 +08:00 · 2152 次点击
    这是一个创建于 2931 天前的主题,其中的信息可能已经有所发展或是发生改变。

    项目地址: https://github.com/huntzhan/magic-parameter

    一句话概括: 周末倒腾出来的 prove of concept project, 可以帮你做传入参数的类型检查.

    简单的例子:

    from magic_parameter import class_init_parameter
    
    @class_init_parameter
    class Example(object):
    
        PARAMETERS = [
            ('a', int),
        ]
    
        def __init__(self):
            print(self.a)
    

    Runtime:

    In [8]: Example(1)
    1
    In [9]: Example(1.0)
    ---------------------------------------------------------------------------
    TypeError            
    ...
    TypeError: Rule:
    name: None
    type: <class 'int'>
    Arg: 1.0
    

    觉得好玩的给个 Star 呀.

    经过与 @RyanKung 讨论 后, 发现还有许多不足, 希望各位可以给点建设性的建议.

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1228 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 18:14 · PVG 02:14 · LAX 11:14 · JFK 14:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.