破解python的参数定义!
magic_parameter的Python项目详细描述
魔法参数构建状态
==
**警告:此项目的接口不稳定,将来可能会在
中更改!**
``magic parameter``为您处理类型检查。
----
:
,<;类型声明>;)``
-`(<;name>;,<;type declaration>;,<;default value>;)``
-`(<;name>;,<;type declaration>;,none)``
类型声明:
-任何**类型对象**,即``list`,``int`,``str`,``foobar`。
-magic para的实例meter.<;嵌套类型>;``:
-`` magic_参数.列表t(<;类型声明>;)``
-`` magic_参数.元组t(<;类型声明>;)`
-`` magic_参数.设置t(<;类型声明>;)``
-`` magic_参数.dict_t(<;键类型声明>;,<;值类型e declaration>;)`
-magic参数的实例。lt;relation type>;``
-`` magic参数。或`(<;type declaration>;,…)`
-`` magic参数。function\u参数`
-`` magic参数。method\u参数`
-`` magic参数。方法初始化参数`
-``魔术参数.类初始化参数`
``函数参数(原始参数decls)`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~接受``int``s的
``list`.
…代码::python
代码::ipython
in[2]:func([1,2,3])
out[2]:[1,2,3]
in[3]:func([1,2.0,3])
类型错误:规则:
名称:none
类型:<;类"int">;
参数:2.0
``方法参数(原始参数值,传递函数值,参数值=false,传递CLS或自属性值=false,在CLS或自属性值=true上没有警告值)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`` method参数``是类方法装饰器。``方法_parameter``
提供两种传递参数的方法:
。按函数参数,与函数参数相同。在这种情况下,
`` pass_by_function_argument``应该设置为'true`.
。绑定到类方法的第一个参数的属性。在这种情况下,"pass_by_cls_或_self_attribute s"应该设置为"true"。
默认情况下,"no_warning_on_cls_或_self_attributes=true`",这意味着属性重写没有警告。
flowing example用两种方法定义一个类:
。`` func1``是一个带参数``a``的``classmethod`,接受一个以``str``为键,以``int`为值的`
``dict``方法。`` func2``是一个带参数``a``的函数,接受``list`
或``tuple`.
代码::python
ion_参数=true,
)
def func1(cls,args):
返回参数a
@method_参数(
[
('a'或'u t(list,tuple)),
],
pass_by_cls_或_self_attributes=true,
)
def func2(self):
return self.a
runtime:
代码::ipython
in[8]:example.func1({'k1':1,'k2':2})
out[8]:{'k1':1,'k2':2}
in[9]:example.func1({'k1':1,1:2})
----------
类型错误回溯(mo最近一次调用最后一次)
…
类型错误:规则:
名称:none
类型:<;class'str'>;
参数:1
[16]:example=example()
[17]:example.func2([1,2,3])
out[17]:[1,2,3]
[18]:example.func2((1,2,3))
ouT[18]:(1,2,3)
在[19]中:示例.func2(1)
-----------------------------------
typeerror traceback(最近一次调用的最后一次)
…
typeerror:1不能匹配[<;magic_参数。类型u dec位于0x1076AC048>;<;0x1076AC080>;<;位于0x1076AC080>;<;<;magic参数.type\u declaration.typedecl对象位于0x1076AC080>;]
``方法初始参数(原始参数)参数(原始参数)参数```
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~方法参数``如果
`` pass_by_cls_或_self_attributes=true,则在'u cls_或_self_attributes=true`
部分绑定时没有任何警告。它旨在声明类方法的参数。
代码::python
代码::ipython
in[3]:示例(1)
1
out[3]:<;\u main\u.示例at 0x1029bda20>;
in[4]:示例(1.0)
——最后一次点名)
……
……
typeerror:规则:
name:none
type:<;class'int'gt;
arg:1.0
``class'u init参数(用户定义的类)参数(用户定义的类)参数`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~类装饰器。``类初始化参数将从用户定义的类中提取参数声明,然后将函数注入用户定义的类中。代码::python
参数=[
('a',int),
]
def\uu init\uu(self):
打印(self.a)
运行时:
代码::ipython
in[5]:示例1(1)
out[5]:<;f.example1 at 0x106b529b0>;
in[6]:示例1(a=1)
out[6]:<;f.example1at 0x106ba83c8>;
in[7]:示例1(1.0)
-----
类型错误回溯(最近一次调用)
…
类型错误:规则:
名称:none
类型:<;class'int'>;
参数:1.0
|构建状态图像::https://travis-ci.org/huntzhan/magic-parameter.svg?分支=主
:目标:https://travis-ci.org/huntzhan/magic-parameter
==
**警告:此项目的接口不稳定,将来可能会在
中更改!**
``magic parameter``为您处理类型检查。
:
,<;类型声明>;)``
-`(<;name>;,<;type declaration>;,<;default value>;)``
-`(<;name>;,<;type declaration>;,none)``
类型声明:
-任何**类型对象**,即``list`,``int`,``str`,``foobar`。
-magic para的实例meter.<;嵌套类型>;``:
-`` magic_参数.列表t(<;类型声明>;)``
-`` magic_参数.元组t(<;类型声明>;)`
-`` magic_参数.设置t(<;类型声明>;)``
-`` magic_参数.dict_t(<;键类型声明>;,<;值类型e declaration>;)`
-magic参数的实例。lt;relation type>;``
-`` magic参数。或`(<;type declaration>;,…)`
-`` magic参数。function\u参数`
-`` magic参数。method\u参数`
-`` magic参数。方法初始化参数`
-``魔术参数.类初始化参数`
``函数参数(原始参数decls)`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~接受``int``s的
``list`.
…代码::python
代码::ipython
in[2]:func([1,2,3])
out[2]:[1,2,3]
in[3]:func([1,2.0,3])
类型错误:规则:
名称:none
类型:<;类"int">;
参数:2.0
``方法参数(原始参数值,传递函数值,参数值=false,传递CLS或自属性值=false,在CLS或自属性值=true上没有警告值)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`` method参数``是类方法装饰器。``方法_parameter``
提供两种传递参数的方法:
。按函数参数,与函数参数相同。在这种情况下,
`` pass_by_function_argument``应该设置为'true`.
。绑定到类方法的第一个参数的属性。在这种情况下,"pass_by_cls_或_self_attribute s"应该设置为"true"。
默认情况下,"no_warning_on_cls_或_self_attributes=true`",这意味着属性重写没有警告。
flowing example用两种方法定义一个类:
。`` func1``是一个带参数``a``的``classmethod`,接受一个以``str``为键,以``int`为值的`
``dict``方法。`` func2``是一个带参数``a``的函数,接受``list`
或``tuple`.
代码::python
ion_参数=true,
)
def func1(cls,args):
返回参数a
@method_参数(
[
('a'或'u t(list,tuple)),
],
pass_by_cls_或_self_attributes=true,
)
def func2(self):
return self.a
runtime:
代码::ipython
in[8]:example.func1({'k1':1,'k2':2})
out[8]:{'k1':1,'k2':2}
in[9]:example.func1({'k1':1,1:2})
----------
类型错误回溯(mo最近一次调用最后一次)
…
类型错误:规则:
名称:none
类型:<;class'str'>;
参数:1
[16]:example=example()
[17]:example.func2([1,2,3])
out[17]:[1,2,3]
[18]:example.func2((1,2,3))
ouT[18]:(1,2,3)
在[19]中:示例.func2(1)
-----------------------------------
typeerror traceback(最近一次调用的最后一次)
…
typeerror:1不能匹配[<;magic_参数。类型u dec位于0x1076AC048>;<;0x1076AC080>;<;位于0x1076AC080>;<;<;magic参数.type\u declaration.typedecl对象位于0x1076AC080>;]
``方法初始参数(原始参数)参数(原始参数)参数```
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~方法参数``如果
`` pass_by_cls_或_self_attributes=true,则在'u cls_或_self_attributes=true`
部分绑定时没有任何警告。它旨在声明类方法的参数。
代码::python
代码::ipython
in[3]:示例(1)
1
out[3]:<;\u main\u.示例at 0x1029bda20>;
in[4]:示例(1.0)
——最后一次点名)
……
……
typeerror:规则:
name:none
type:<;class'int'gt;
arg:1.0
``class'u init参数(用户定义的类)参数(用户定义的类)参数`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~类装饰器。``类初始化参数将从用户定义的类中提取参数声明,然后将函数注入用户定义的类中。代码::python
参数=[
('a',int),
]
def\uu init\uu(self):
打印(self.a)
运行时:
代码::ipython
in[5]:示例1(1)
out[5]:<;f.example1 at 0x106b529b0>;
in[6]:示例1(a=1)
out[6]:<;f.example1at 0x106ba83c8>;
in[7]:示例1(1.0)
-----
类型错误回溯(最近一次调用)
…
类型错误:规则:
名称:none
类型:<;class'int'>;
参数:1.0
|构建状态图像::https://travis-ci.org/huntzhan/magic-parameter.svg?分支=主
:目标:https://travis-ci.org/huntzhan/magic-parameter