Modify ↓
Ticket #80 (closed defect: wontfix)
yaml.load doesn't work as i suspect it to according to the documentation
| Reported by: | anonymous | Owned by: | xi |
|---|---|---|---|
| Priority: | normal | Component: | pyyaml |
| Severity: | normal | Keywords: | |
| Cc: |
Description
quote from the documentation:
>>> class Monster(yaml.YAMLObject):
... yaml_tag = u'!Monster'
... def __init__(self, name, hp, ac, attacks):
... self.name = name
... self.hp = hp
... self.ac = ac
... self.attacks = attacks
... def __repr__(self):
... return "%s(name=%r, hp=%r, ac=%r, attacks=%r)" % (
... self.__class__.__name__, self.name, self.hp, self.ac, self.attacks)
>>> yaml.load("""
... --- !Monster
... name: Cave spider
... hp: [2,6] # 2d6
... ac: 16
... attacks: [BITE, HURT]
... """)
the thing is, yaml.load ignores the __init__ method of the Monster class. it doesn't even matter if it's there at all. in yaml.load you can specify aditional variables and they get added to the object. intended behaviour?
Attachments
Change History
comment:2 Changed 5 years ago by anonymous
maybe it would be best then to mention it in the documentation to prevent others like me wondering what's goind wrong :) because i think the line
Monster(name='Cave spider', hp=[2, 6], ac=16, attacks=['BITE', 'HURT'])
that is printed as a representation of the loaded object in the documentation is a bit misleading as it's not actually what get's called apparently
Note: See
TracTickets for help on using
tickets.

Duplicate of #48, see my comment there.