推荐学习书目
› 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 · Apr 18, 2016 · 3020 views
    This topic created in 3818 days ago, the information mentioned may be changed or developed.

    项目地址: 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 讨论 后, 发现还有许多不足, 希望各位可以给点建设性的建议.

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2418 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 07:23 · PVG 15:23 · LAX 00:23 · JFK 03:23
    ♥ Do have faith in what you're doing.