Skip to content

Add type hinting to returned objects #606

@LSgeo

Description

@LSgeo

Is your feature request related to a problem? Please describe.
I'm developing gswa-skippy, which heavily uses lasio in its objective to standardise las file contents. Because lasio doesn't type hint the returned objects from functions and methods, IDEs determine what most returned objects are, and can't provide intellisense suggestions for the returned object. This affects IDEs other than VScode.

To fix this, we would need to add a return type to common functions and methods, using the syntax def function(param: Type) -> ReturnedType:.

I think I can spare some development time (or at least some of my colleagues) if that would help get this implemented, at least for some sections of the library - but it would be great to have a maintainer on board to review / liaise with.

Describe the solution you'd like
For example, Lasio.LASFile.depth_m returns a numpy array. I've added "-> np.ndarray" to its definition below.

    @property
    def depth_m(self) -> np.ndarray
        """Return the index as metres."""
        if self._index_unit_contains("M"):
            return self.index
        elif self._index_unit_contains("F"):
            return self.index * 0.3048
        elif self._index_unit_contains(".1IN"):
            return (self.index / 120) * 0.3048
        else:
            raise exceptions.LASUnknownUnitError("Unit of depth index not known")

I think it also needs a blank py.typed file added to the library somewhere to indicate that the package has been type hinted.

Describe alternatives you've considered
More information and alternatives are at this link: https://typing.python.org/en/latest/spec/distributing.html#packaging-typed-libraries

Additional context
Thanks for the great LAS handling library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions