python3-cookbook icon indicating copy to clipboard operation
python3-cookbook copied to clipboard

8.13小节 使用类装饰器案例未实例化

Open abookworm opened this issue 5 months ago • 0 comments

位置:

  • 8.13小节 使用类装饰器案例
  • pdf 270 页

当前原文:

# Example
@check_attributes(name=SizedString(size=8),
                  shares=UnsignedInteger,
                  price=UnsignedFloat)
class Stock:
    def __init__(self, name, shares, price):
        self.name = name
        self.shares = shares
        self.price = price
  • 此处装饰器中 shareprice 字段未示例化,类型为 <class 'type'>
  • 此处应该实例化为 <class '__main__.UnsignedInteger'>,即:shares=UnsignedInteger(), price=UnsignedFloat()

改正后内容:

# Example
@check_attributes(name=SizedString(size=8),
                  shares=UnsignedInteger(),
                  price=UnsignedFloat())
class Stock:
    def __init__(self, name, shares, price):
        self.name = name
        self.shares = shares
        self.price = price

望解答指正~

abookworm avatar Sep 08 '24 04:09 abookworm