Repository: lhotse-speech/lhotse

Issue:
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getchildren'
since Py 3.9 the function getchildren() in etree seems to be removed (was deprecated since long before, AFAIK)
Affects AMI corpus preparation
```
(py3) [jtrmal@test4 ami_lhotse]$ lhotse prepare ami --partition full-corpus-asr --normalize-text  /expscratch/mwiesner/miniscale_2022_data/Data/amicorpus .
2022-01-13 12:01:58,314 INFO [ami.py:554] Parsing AMI annotations
Traceback (most recent call last):
  File "/home/hltcoe/jtrmal/miniconda3/envs/py3/bin/lhotse", line 33, in <module>
    sys.exit(load_entry_point('lhotse', 'console_scripts', 'lhotse')())
  File "/home/hltcoe/jtrmal/miniconda3/envs/py3/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/hltcoe/jtrmal/miniconda3/envs/py3/lib/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/hltcoe/jtrmal/miniconda3/envs/py3/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/hltcoe/jtrmal/miniconda3/envs/py3/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/hltcoe/jtrmal/miniconda3/envs/py3/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/hltcoe/jtrmal/miniconda3/envs/py3/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/hltcoe/jtrmal/lhotse/lhotse/bin/modes/recipes/ami.py", line 47, in ami
    prepare_ami(
  File "/home/hltcoe/jtrmal/lhotse/lhotse/recipes/ami.py", line 565, in prepare_ami
    annotations = parse_ami_annotations(annotations_dir, normalize_text)
  File "/home/hltcoe/jtrmal/lhotse/lhotse/recipes/ami.py", line 342, in parse_ami_annotations
    assert len(seg.getchildren()) == 1, "Multiple child segments found"
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getchildren'
```


Discussion:
@pzelasko let me know if I'm (not) right and if you want me to fix it

Thanks for reporting. I don't know about it as I rarely work with XML these days. If you know how to fix that, it'd be a welcome contribution.
ack, will do tomorrow.
y.

On Thu, Jan 13, 2022 at 6:19 PM Piotr Żelasko ***@***.***>
wrote:

> Thanks for reporting. I don't know about it as I rarely work with XML
> these days. If you know how to fix that, it'd be a welcome contribution.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/lhotse-speech/lhotse/issues/535#issuecomment-1012343520>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ACUKYX4OQ4UJ6XY5P23PH43UV4CQJANCNFSM5L4MWZIA>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>

fixes are kinda trivial, I'm more surprised no-one has complained yet :) So I wonder if I'm just not doing something right
@jimbozhang and @desh2608 might know more as they are the main contributors of that recipe IIRC
@jtrmal good catch! I didn't try the recipe with Python 3.9 so I wasn't aware of this issue (and somehow also missed deprecation warnings). I suppose the only change needed is seg.getchildren()--> list(seg). Could you make a PR with the fix?
yeah, will do

On Fri, Jan 14, 2022 at 3:43 AM Desh Raj ***@***.***> wrote:

> @jtrmal <https://github.com/jtrmal> good catch! I didn't try the recipe
> with Python 3.9 so I wasn't aware of this issue (and somehow also missed
> deprecation warnings). I suppose the only change needed is
> seg.getchildren()--> list(seg). Could you make a PR with the fix?
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/lhotse-speech/lhotse/issues/535#issuecomment-1012699104>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ACUKYX6LWCKYLBGFGC7INQ3UV6EVLANCNFSM5L4MWZIA>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>


Resolving patch:
diff --git a/lhotse/recipes/ami.py b/lhotse/recipes/ami.py
--- a/lhotse/recipes/ami.py
+++ b/lhotse/recipes/ami.py
@@ -339,8 +339,8 @@ def _parse_href(href, wid_to_word):
                     continue
                 start_time = float(seg.attrib["transcriber_start"])
                 end_time = float(seg.attrib["transcriber_end"])
-                assert len(seg.getchildren()) == 1, "Multiple child segments found"
-                seg_child = seg.getchildren()[0]
+                assert len(seg) == 1, "Multiple child segments found"
+                seg_child = next(iter(seg))
                 if "href" in seg_child.attrib:
                     text = _parse_href(seg_child.attrib["href"], wid_to_word)
                 annotations[key].append(


Test patch: