elifesciences / elife-tools

Python library for parsing eLife article XML data.
MIT License
15 stars 7 forks source link

In utils.first(), use exceptions for non-iterable #436

Closed gnott closed 10 months ago

gnott commented 10 months ago

I noticed this, which seems to work, otherwise the TypeError exception is not raised when the argument is a list.

lsh-0 commented 10 months ago

That's intentional, actually. The problem might be that after wrapping in iter(...) it's difficult to find a type that now raises a TypeError in which the fallback (someval[0]) would then succeed.

gnott commented 10 months ago

Ah, ok, only the test coverage reported those lines were not triggered, I like the added safety.

gnott commented 10 months ago

eh, it works. go for it.

I like your reasoning instead, thanks for taking a look.