ywangd / pybufrkit

Pure Python toolkit to work with WMO BUFR messages
http://pybufrkit.readthedocs.io/
MIT License
72 stars 28 forks source link

iter(query_result) fails with AttributeError #23

Open gerritholl opened 1 year ago

gerritholl commented 1 year ago

The QueryResult class in the dataquery module defines a method __iter__. Calling this method unconditionally fails with AttributeError, due to calling a historical dict method viewitems that existed in Python 2.

To reproduce:

from pybufrkit.decoder import Decoder, generate_bufr_message
from pybufrkit.dataquery import NodePathParser, DataQuerent
fn = "/home/gholl/checkouts/pybufrkit/tests/data/jaso_214.bufr"
with open(fn, "rb") as fp:
    for bufr_message in generate_bufr_message(Decoder(), fp.read()):
        query_result = DataQuerent(NodePathParser()).query(bufr_message, '001015')
        iter(query_result)

Using Python 3.11, this fails with:

Traceback (most recent call last):
  File "/data/gholl/checkouts/protocode/mwe/pybufrkit-attributeerror.py", line 7, in <module>
    iter(query_result)
  File "/data/gholl/mambaforge/envs/py311/lib/python3.11/site-packages/pybufrkit/dataquery.py", line 313, in __iter__
    return iter(self.results.viewitems())
                ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'collections.OrderedDict' object has no attribute 'viewitems'

I'm using pybufrkit 0.2.19.