cldf / pycldf

python package to read and write CLDF datasets
https://cldf.clld.org
Apache License 2.0
15 stars 7 forks source link

Dataset.__contains__ falls back to Dataset.__getitem__, badly. #132

Closed Anaphory closed 3 years ago

Anaphory commented 3 years ago

I just happened to wonder whether I could, by chance, test ("FormTable", "cognatesetReference") in ds.

(NB: some of the pre-1.0-stuff we back then used in BEASTling used that kind of format for cognates, so I thought such data sets might exist elsewhere, too, but the specifics of my example are not really relevant to this discussion.)

That expression gets a cryptic AttributeError: 'int' object has no attribute 'startswith', because as per https://docs.python.org/3.10/reference/expressions.html#membership-test-operations __contains__ falls back to testing __getitem__ for all non-negative integers in sequence, and that's completely not what

https://github.com/cldf/pycldf/blob/384f7c5227bd467c347643bd50249c66f0559a23/src/pycldf/dataset.py#L605-L630

expects. This is quite a fringe case for pycldf, actually, so – is it worth implementing a clean __contains__ to avoid people running into this?

xrotwang commented 3 years ago

fix released in pycldf 1.20.2