Skip to content

Python type hints don't declare optional values #1310

@gmacon

Description

@gmacon

Describe the bug

Some functions in the Python API have documentation that they return something or None if the something doesn't exist, but the type hints don't reflect that. As a concrete example, the documentation for lief.PE.Binary.get_section says:

Return the Section object from the given name or None if not not found

but the type signature for this method is

def get_section(self, section_name: str) -> Section: ...

which implies that it never returns None.

Expected behavior
Any function (or attribute) that can return (or be) None, should be so annotated, e.g.

def get_section(self, section_name: str) -> Section | None: ...

Environment (please complete the following information):

  • System and Version : Ubuntu 22.04
  • Target format (PE, ELF, Mach-O): PE
  • LIEF commit version: cbf06a5

Additional context

These are the spots I've run into this so far:

  • lief.PE.Binary.get_export
  • lief.PE.Binary.get_section

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions