Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hoangduytran opened this issue Mar 12, 2024 · 1 comment
Open

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

hoangduytran opened this issue Mar 12, 2024 · 1 comment

Comments

@hoangduytran
Copy link

hoangduytran commented Mar 12, 2024

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

@jayaddison
Copy link
Contributor

Thanks for the bugreport @hoangduytran. Are you able to determine how/where these non-picklable catalog items were created?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants