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

Remove remaining legacy Python 2 code #599

Merged
merged 6 commits into from
Feb 25, 2025
Merged

Remove remaining legacy Python 2 code #599

merged 6 commits into from
Feb 25, 2025

Conversation

pmhahn
Copy link
Contributor

@pmhahn pmhahn commented Feb 24, 2025

pyelftools is Python 3 only, but the code still carries some Python 2 legacy code.

  • print is a function
  • instead of OrderedDict use dict which is also ordered since cPython 3.6 – it still has its uses for things like LRU-caching, but that is not the case here
  • remove unneeded code when inheriting from colklections.MutableMapping
  • remove py3compatlayer from Construct – simplifies the code and future type hinting Add static typing #514

@pmhahn pmhahn mentioned this pull request Feb 24, 2025
Copy link
Owner

@eliben eliben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, very nice cleanup overall!

<https://docs.python.org/3/library/collections.html#ordereddict-objects>:
> Ordered dictionaries are just like regular dictionaries but have some
> extra capabilities relating to ordering operations. They have become
> less important now that the built-in dict class gained the ability to
> remember insertion order (this new behavior became guaranteed in
> Python 3.7).

Signed-off-by: Philipp Hahn <[email protected]>
`collections.abc.MutableMapping` already implements `keys()`,
`update()`, `__eq__()`, `__ne__()` and `__contains__()` – most
importantly correctly, e.g. `update()` has many variants which the
current implementation does not handle.

Signed-off-by: Philipp Hahn <[email protected]>
Remove the compatibility layer `py3compat`.

PS: There is eliben#548 to migrate
from the interned version of `construct` back to "Construct 2.10+" now
that it is maintained again. When that happens, this change will become
moot. Until then restore some sanity back into our copy as handling
Python type annotations for both Python 2 and 3 is a major pain.

Signed-off-by: Philipp Hahn <[email protected]>
The project is Python 3 only, so remove the legacy Python 2
compatibility.

Signed-off-by: Philipp Hahn <[email protected]>
The function was used in only one place. Just use the much more
efficient `bytes(list[int])` to convert from `list[int]` to `bytes`.

Signed-off-by: Philipp Hahn <[email protected]>
@eliben eliben merged commit f92bb71 into eliben:main Feb 25, 2025
4 checks passed
@pmhahn pmhahn deleted the python3 branch February 25, 2025 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants