transientskp / pyse

Python Source Extractor
BSD 2-Clause "Simplified" License
11 stars 5 forks source link

Reimplement dataaccessor #66

Closed HannoSpreeuw closed 1 month ago

HannoSpreeuw commented 1 month ago

Following @suvayu on replacing DataAccessor by a dataclass. DataAccessor was inheriting from RequiredAttributesMetaclass. This way of enforcing required attributes seems too heavy machinery and the dataclass is a a lightweight solution.

Should also fix #53

HannoSpreeuw commented 1 month ago

Probably some loose ends although all unit tests pass, since hatch run lint:mypy yields

sourcefinder/utility/containers.py:55: error: Signatures of "__iadd__" and "__add__" are incompatible  [misc]
sourcefinder/accessors/lofarhdf5image.py:9: error: Missing positional arguments "beam", "centre_ra", "centre_decl", "data", "freq_bw", "freq_eff", "pixelsize", "tau_time", "taustart_ts", "url", "wcs" in call to "__init__" of "DataAccessor"  [call-arg]
sourcefinder/accessors/lofarhdf5image.py:62: error: "LofarHdf5Image" has no attribute "header"  [attr-defined]
sourcefinder/accessors/fitsimageblob.py:45: error: Signature of "_get_header" incompatible with supertype "FitsImage"  [override]
sourcefinder/accessors/fitsimageblob.py:45: note:      Superclass:
sourcefinder/accessors/fitsimageblob.py:45: note:          def _get_header(self, hdu_index: Any) -> Any
sourcefinder/accessors/fitsimageblob.py:45: note:      Subclass:
sourcefinder/accessors/fitsimageblob.py:45: note:          def _get_header(self, hdulist: Any, hdu_index: Any) -> Any
sourcefinder/accessors/fitsimageblob.py:48: error: Signature of "read_data" incompatible with supertype "FitsImage"  [override]
sourcefinder/accessors/fitsimageblob.py:48: note:      Superclass:
sourcefinder/accessors/fitsimageblob.py:48: note:          def read_data(self, hdu_index: Any, plane: Any) -> Any
sourcefinder/accessors/fitsimageblob.py:48: note:      Subclass:
sourcefinder/accessors/fitsimageblob.py:48: note:          def read_data(self, hdulist: Any, hdu_index: Any, plane: Any) -> Any
Found 5 errors in 3 files (checked 30 source files)
HannoSpreeuw commented 1 month ago

The line sourcefinder/accessors/lofarhdf5image.py:61: error: "LofarHdf5Image" has no attribute "header" [attr-defined] from the mypy output has to do with

    def get_header(self):
        # Preserved for API compatibility.
        return self.header

Apparently not implemented yet.

Should not be solved as part of this PR.

HannoSpreeuw commented 1 month ago

The other mypy complaints have been taken care of through commit d163f9b.

HannoSpreeuw commented 1 month ago

Allright. So that means DataAccessor has been adequately reimplemented, but the design of its derived classes may need improvements.