astpath icon indicating copy to clipboard operation
astpath copied to clipboard

`TypeError: 'float' object is not iterable` when attempting to emit a count of elements

Open OddBloke opened this issue 4 years ago • 0 comments

I'm currently using astpath to determine if we need a function's lone keyword to be optional, or if all of its callers pass it and therefore we can make it unconditionally required. I can get a list of callsites which use it:

$ astpath './/Call[func[Name[@id="report_diagnostic_event"]] and count(keywords) = 1]' -d cloudinit | wc -l
46

and then I thought I'd get clever:

$ astpath 'count(.//Call[func[Name[@id="report_diagnostic_event"]] and count(keywords) = 1])' -d cloudinit
Traceback (most recent call last):
  File "/home/daniel/.virtualenvs/cloud-init/bin/astpath", line 8, in <module>
    sys.exit(main())
  File "/home/daniel/.virtualenvs/cloud-init/lib/python3.8/site-packages/astpath/cli.py", line 37, in main
    search(
  File "/home/daniel/.virtualenvs/cloud-init/lib/python3.8/site-packages/astpath/search.py", line 149, in search
    file_matches = find_in_ast(
  File "/home/daniel/.virtualenvs/cloud-init/lib/python3.8/site-packages/astpath/search.py", line 42, in find_in_ast
    for result in results:
TypeError: 'float' object is not iterable

I don't really know if I'm specifying valid XPath, but if this should work then I'd like it to (and if it shouldn't then perhaps a friendlier error message?).

OddBloke avatar Sep 17 '20 15:09 OddBloke