Skip to content

Stop accessing None as a dictionary #292

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

Merged
merged 1 commit into from
Apr 12, 2025
Merged

Conversation

hroncok
Copy link
Contributor

@hroncok hroncok commented Jul 3, 2024

PyMapping_HasKeyString does not work on None
Accidentally, it used to return false result on silent errors.

Since Python 3.13, this is what happens instead:

>>> import pylibmc
>>> m = pylibmc.Client(["10.0.0.1"], binary=True)
Exception ignored in PyMapping_HasKeyString(); consider using PyMapping_HasKeyStringWithError(), PyMapping_GetOptionalItemString() or PyMapping_GetItemString():
Traceback (most recent call last):
  File "/usr/lib64/python3.13/site-packages/pylibmc/client.py", line 142, in __init__
    super().__init__(servers=translate_server_specs(servers),
TypeError: 'NoneType' object is not subscriptable
...
Exception ignored in PyMapping_HasKeyString(); consider using PyMapping_HasKeyStringWithError(), PyMapping_GetOptionalItemString() or PyMapping_GetItemString():
Traceback (most recent call last):
  File "/usr/lib64/python3.13/site-packages/pylibmc/client.py", line 142, in __init__
    super().__init__(servers=translate_server_specs(servers),
TypeError: 'NoneType' object is not subscriptable

When this is run via pytest, it leads to:

pytest.PytestUnraisableExceptionWarning: Exception ignored in PyMapping_HasKeyString(); consider using PyMapping_HasKeyStringWithError(), PyMapping_GetOptionalItemString() or PyMapping_GetItemString(): None

Fixes pallets-eco/cachelib#400

PyMapping_HasKeyString does not work on None
Accidentally, it used to return false result on silent errors.

Since Python 3.13, this is what happens instead:

    >>> import pylibmc
    >>> m = pylibmc.Client(["10.0.0.1"], binary=True)
    Exception ignored in PyMapping_HasKeyString(); consider using PyMapping_HasKeyStringWithError(), PyMapping_GetOptionalItemString() or PyMapping_GetItemString():
    Traceback (most recent call last):
      File "/usr/lib64/python3.13/site-packages/pylibmc/client.py", line 142, in __init__
        super().__init__(servers=translate_server_specs(servers),
    TypeError: 'NoneType' object is not subscriptable
    ...
    Exception ignored in PyMapping_HasKeyString(); consider using PyMapping_HasKeyStringWithError(), PyMapping_GetOptionalItemString() or PyMapping_GetItemString():
    Traceback (most recent call last):
      File "/usr/lib64/python3.13/site-packages/pylibmc/client.py", line 142, in __init__
        super().__init__(servers=translate_server_specs(servers),
    TypeError: 'NoneType' object is not subscriptable

When this is run via pytest, it leads to:

    pytest.PytestUnraisableExceptionWarning: Exception ignored in PyMapping_HasKeyString(); consider using PyMapping_HasKeyStringWithError(), PyMapping_GetOptionalItemString() or PyMapping_GetItemString(): None

Fixes pallets-eco/cachelib#400
@rh-anocca
Copy link

Can this please be merged?

@ingkebil
Copy link

I'd appreciate a quick merge on this as well. Since upgrading to p3.13, these messages are severely clogging up our logs.

@ingkebil
Copy link

Is there any reason this cannot be merged?

@lachesis
Copy link

I think the main reason this cannot be merged is just that nobody is maintaining this repo anymore.

@lericson
Copy link
Owner

You can complain about my attendance to this project when you pay my rent, @lachesis.

@lericson lericson merged commit d8d3f46 into lericson:master Apr 12, 2025
@lericson
Copy link
Owner

Thanks, we should probably have a test for this, but 🤷

@lachesis
Copy link

No complaint, just telling it how I see it. I've got my own share of unmaintained projects! Appreciate the review and merge. Now I can drop my fork and go back to using the mainline.

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