NCAS-CMS / cfunits

A Python interface to UNIDATA’s UDUNITS-2 library with CF extensions:
http://ncas-cms.github.io/cfunits
MIT License
11 stars 8 forks source link

Fix `doctest` failures for Python 3.10+ on `AttributeError` messages #56

Closed sadielbartholomew closed 7 months ago

sadielbartholomew commented 7 months ago

Quick one to fix some doctest failures for a full tests suite pass across supported Python 3.X versions. Notably there were a few failures due to the feature introduced in Python 3.10 which adds "Did you mean ..." suggestions to some error messages, such that Python 3.8 gives a shorter AttributeError and in the affected cases:

Python 3.8.17 | packaged by conda-forge | (default, Jun 16 2023, 07:06:00) 
[GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cfunits
>>> cfunits.Units('days since 2000-1-1').calendar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/slb93/git-repos/cfunits/cfunits/units.py", line 1775, in calendar
    raise AttributeError(
AttributeError: Units has no attribute 'calendar'

whereas e.g. Python 3.12 will show the extended message:

Python 3.12.0 | packaged by conda-forge | (main, Oct  3 2023, 08:43:22) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cfunits
>>> cfunits.Units('days since 2000-1-1').calendar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/slb93/git-repos/cfunits/cfunits/units.py", line 1775, in calendar
    raise AttributeError(
AttributeError: Units has no attribute 'calendar'. Did you mean: '_calendar'?

The ellipsis ... marker indicates to doctest any or no text at that location is acceptable and will ensure the tests pass for both message versions, and users can interpret it in the natural way as 'there may be further text after this', so it works for both machine and human.

sadielbartholomew commented 7 months ago

Hmm, noticing now that there are plenty of setup issues with the CI workflows, very likely due to it being out-of-date. I'll try to address those shortly. As for this PR, the results aren't useful so I'll merge straight away.

Trivial change so no review requested/required.