Custom Query (121 matches)


Show under each result:

Results (22 - 24 of 121)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Ticket Resolution Summary Owner Reporter
#39 fixed yaml.load("") raises an exception xi iusty@…

Reported by iusty@…, 11 years ago.


With the latest PyYAML (3.04):

$ python
Python 2.4.4 (#2, Oct 19 2006, 23:03:48) 
[GCC 4.1.2 20061007 (prerelease) (Debian 4.1.1-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
>>> yaml.load("")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local//lib/python2.4/site-packages/yaml/", line 66, in load
    return loader.get_data()
  File "/usr/local//lib/python2.4/site-packages/yaml/", line 38, in get_data
    return self.construct_document(self.get_node())
  File "/usr/local//lib/python2.4/site-packages/yaml/", line 23, in get_node
    return self.compose_document()
  File "/usr/local//lib/python2.4/site-packages/yaml/", line 35, in compose_document
    node = self.compose_node(None, None)
  File "/usr/local//lib/python2.4/site-packages/yaml/", line 52, in compose_node
    anchor = event.anchor
AttributeError: 'NoneType' object has no attribute 'anchor'

I think this is a bug - at least it should raise a yaml.scanner.ScannerError?, like yaml.load("'") does, and then it can be easily catched as a malformed stream. Right now, it's hard to deal with this.

Thanks, Iustin

#41 fixed Patch: Use types module instead of hand crafted entities and type(). xi v.haisman@…

Reported by v.haisman@…, 11 years ago.


Hi, I have a patch that makes PyYAML use types module instead of hand crafted entities and type(). The motivation is that it silences some PyDev? error complains, like methods not having self parameter and such.

#43 fixed path resolver has bug xi jstroud@…

Reported by jstroud@…, 11 years ago.


Path resolving does not work for Nodes within Sequence Nodes

[This is current for pyyaml 3.04.]

For example:

yaml.add_path_resolver(u'!MyObject', (u'myobjs', [list, False]))

should match all of the items in the myobjs sequence in this yaml:

--- !MyConfig
myobjs :
    - name: x
      root: z
    - name: p
      root: q

The problem is here in (line 210):

elif isinstance(index_check, int):
    if index_check != current_index:

If I'm infering the intent of the code correctly

(u'myobjs', (list, False))

should match all elements of the sequence keyed by "myobjs". However,

isinstance(False, int)

always returns True because bool is a subclass of int, so index_check will only equal current_index for the first element when False is specified as the index_check.

Additionally, I believe another bug exists in According to the code in add_path_resolver(), index_check defaults to True when not specified (, line 39):

if isinstance(element, (list, tuple)):
    if len(element) == 2:
        node_check, index_check = element
    elif len(element) == 1:
        node_check = element[0]
        index_check = True

The intendend meaning of True here is not clear because True causes every element in the sequence to fail the match. The relevant test is in check_resolver_prefix() (, line 116):

if index_check is True and current_index is not None:

Thus, any path not specifying an index_check will never match. Most insidious to the user is that this case is never reported nor an exception thrown. If index_check is True, this code will only continue to test if current_index is None, which should never happen for any node of any sequence, because any node of a sequence must, by virtue of its existence, have an index.

To fix these problems, I propose the following patch to

<                     index_check = True
>                     index_check = False
<         elif isinstance(index_check, int):
>         elif isinstance(index_check, int) and index_check is not False:

This will set the default value of index_check to match all elements of a sequence if no index_check is given and will not attempt to compare False to the value of index_check.

At the bare minimum, the following patch should be strongly considered if a good reason exists to leave the defalut of index_check to True.

<         elif isinstance(index_check, int):
>         elif isinstance(index_check, int) and index_check is not False:

Moreover, the code should provide some indication for what an index_check value of True actually means.

In fact, I propose re-writing the code to use None to match all elements, because

isinstance(None, int)

will always evaluate to False. This will also remove the question as to what the "other" bool value means because bools will not be used. I can provide a patch if this latter proposal sounds good to the developers.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Note: See TracQuery for help on using queries.