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

Ressources deprecation does not work for some python versions #2697

Closed
ztravis opened this issue May 31, 2024 · 2 comments · Fixed by #2705
Closed

Ressources deprecation does not work for some python versions #2697

ztravis opened this issue May 31, 2024 · 2 comments · Fixed by #2705
Labels
is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF

Comments

@ztravis
Copy link
Contributor

ztravis commented May 31, 2024

The Ressources object under pypdf.constants was deprecated and replaced with a correctly-spelled variant. The deprecated version uses @classmethod @property static-esque properties so that a deprecation message can be logged, but I think this is only supported in a limited range of python versions (3.9 and 3.10) according to https://docs.python.org/3/library/functions.html#classmethod.
For example, on python3.8 these end up being type method, which causes unexpected behavior when they're used (e.g. as object keys), e.g.:

x = DictionaryObject()
x[NameObject(Ressources.EXT_G_STATE)] = DictionaryObject()
x.write_to_stream(stream) # Writes b"<<\n<bound#20method#20?#20of#20<class#20'pypdf.constants.Ressources'>> <<\n>>\n>>"
@stefan6419846
Copy link
Collaborator

Thanks for the report. Do you want to submit a corresponding PR to fix this?

It there are no other easier ways to achieve this, I would recommend to copy and re-use the classproperty implementation from Django with appropriate attribution (the license is compatible): https://docs.djangoproject.com/en/5.0/_modules/django/utils/functional/#classproperty

@stefan6419846 stefan6419846 added the is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF label May 31, 2024
stefan6419846 added a commit to stefan6419846/pypdf that referenced this issue Jun 6, 2024
pubpub-zz pushed a commit that referenced this issue Jun 7, 2024
* BUG: fix deprecation for Ressources when using old constants

Fixes #2697

* fix for ruff

* fix mypy

* fix mypy

* move class to fix circular import

* add test overriding classproperty getter

* fix ruff
@ztravis
Copy link
Contributor Author

ztravis commented Jun 7, 2024

Sorry I missed your comment! Thank you for the suggestion and fix. Next time I will be happy to open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants