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

Minor fixes while adding type annotaions #600

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

pmhahn
Copy link
Contributor

@pmhahn pmhahn commented Feb 24, 2025

While working on #514 I – more correctly: mypy – found two minor issues:

  • remove duplicate definition of ENUM_SUNW_SYMINFO_BOUNDTO
  • make several methods as @staticmethod as they are used as functions.

- 5db2966 introduced it first as `ENUM_SYMINFO_BOUNDTO`
- 594dc72 renamed it to `ENUM_SUNW_SYMINFO_BOUNDTO`
- 7b24670 added it a 2nd time

Signed-off-by: Philipp Hahn <phahn-oss@avm.de>
@pmhahn pmhahn mentioned this pull request Feb 24, 2025
A method expects `self` as the first argument; they are all functions.

But: they are all de-referenced already during class definition, at
which point they are actually functions; they only become methods after
the `class` scope is finished.

```console
$ test/all_tests.py
E........EE...................E.....E.....E.....................................................................
======================================================================
ERROR: test_reloc (test_arm_call_reloc.TestARMRElocation)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "…/pyelftools/test/test_arm_call_reloc.py", line 41, in test_reloc
    self.assertEqual(do_relocation(rel_elf),
  File "…/pyelftools/test/test_arm_call_reloc.py", line 28, in do_relocation
    rh.apply_section_relocations(stream, rel)
  File "…/pyelftools/elftools/elf/relocation.py", line 238, in apply_section_relocations
    self._do_apply_relocation(stream, reloc, symtab)
  File "…/pyelftools/elftools/elf/relocation.py", line 319, in _do_apply_relocation
    relocated_value = recipe.calc_func(
TypeError: 'staticmethod' object is not callable
```

For clarity move all those functions into a separate class.

Signed-off-by: Philipp Hahn <phahn-oss@avm.de>
@@ -340,167 +340,176 @@ def _do_apply_relocation(self, stream, reloc, symtab):
_RELOCATION_RECIPE_TYPE = namedtuple('_RELOCATION_RECIPE_TYPE',
'bytesize has_addend calc_func')

def _reloc_calc_identity(value, sym_value, offset, addend=0):
Copy link
Owner

Choose a reason for hiding this comment

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

Interesting that this is a problem; is mypy complaining that these methods don't take a self?

For standalone functions, we can just make them standalone (move outside the calss) instead of adding an internal class, no?

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