Skip to content

Catalog._cmp_ function needed to cater for None object #12064

@hoangduytran

Description

@hoangduytran

Describe the bug

When running dill to detect any bad items for pickle, dill returns error on this function, when trying to compare with a None object.

How to Reproduce

run pip3 install dill

then do

import dill
from sphinx_intl import catalog as c

dill.detect.trace(True)
po_path = <path to po file>
cat: Catalog = c.load_po(po_path)
dill.detect.baditems(cat)

it will say something like this:

File "../lib/python3.9/site-packages/babel/messages/catalog.py", line 169, in values_to_compare
return obj.id, obj.context or ''
AttributeError: 'NoneType' object has no attribute 'id'

if you correct this function by doing this:

def values_to_compare(obj):
            is_none = (obj is None)
            if is_none: # adding blank key for None type object
                return ('', '')

            # print(f'values_to_compare obj:{obj}')
            if isinstance(obj, Message) and obj.pluralizable:
                return obj.id[0], obj.context or ''

            return obj.id, obj.context or ''

then it works

Environment Information

sphinx==7.2.6

# Sphinx dependencies that are important
Jinja2==3.1.2
Pygments==2.16.1
docutils==0.18.1
snowballstemmer==2.2.0
babel==2.13.0
requests==2.31.0

# Only needed for building translations.
sphinx-intl==2.1.0

# Only needed to match the theme used for the official documentation.
# Without this theme, the default theme will be used.
sphinx_rtd_theme==2.0.0rc4

# Only for convenience, allows live updating while editing RST files.
# Access by running:
#   make livehtml
sphinx-autobuild==2021.3.14

# Required for spell-checking
pyenchant

Sphinx extensions

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions