Modify

Ticket #80 (closed defect: wontfix)

Opened 6 years ago

Last modified 6 years ago

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:1 Changed 6 years ago by xi

  • Status changed from new to closed
  • Resolution set to wontfix

Duplicate of #48, see my comment there.

comment:2 Changed 6 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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.