22
33from __future__ import annotations
44
5- from typing import TYPE_CHECKING
6-
75import logging
6+ from typing import TYPE_CHECKING
87
98import numpy as np
109import numpy .typing as npt
1918from mdio .core .exceptions import MDIONotFoundError
2019from mdio .exceptions import ShapeError
2120
21+
2222if TYPE_CHECKING :
2323 import dask .array as da
2424 from numpy .typing import NDArray
2525
2626logger = logging .getLogger (__name__ )
2727
2828
29- class MDIOAccessor :
29+ class MDIOAccessor : # noqa: DOC502
3030 """Accessor class for MDIO files.
3131
3232 The accessor can be used to read and write MDIO files. It allows you to
@@ -138,7 +138,7 @@ class MDIOAccessor:
138138 "dask" : open_zarr_array_dask ,
139139 }
140140
141- def __init__ (
141+ def __init__ ( # noqa: PLR0913
142142 self ,
143143 mdio_path_or_buffer : str ,
144144 mode : str ,
@@ -150,7 +150,6 @@ def __init__(
150150 memory_cache_size : int ,
151151 disk_cache : bool ,
152152 ):
153- """Accessor initialization function."""
154153 # Set public attributes
155154 self .url = mdio_path_or_buffer
156155 self .mode = mode
@@ -180,11 +179,24 @@ def __init__(
180179
181180 # Call methods to finish initialization
182181 self ._validate_store (storage_options )
183- self ._connect ()
182+ self ._connect () # noqa: DOC502
184183 self ._deserialize_grid ()
185184 self ._set_attributes ()
186185 self ._open_arrays ()
187186
187+ if False :
188+ """
189+ This code block is inert and is intended only to satisfy the linter.
190+
191+ Pre-commit linting causes some issues.
192+ The __init__ method raises an error from the _connect method.
193+ Since the error isn't raised directly from the __init__ method,
194+ the linter complains and the noqa: DOC502 is ignored.
195+ Disabling the DOC502 globally is not desirable.
196+ """
197+ err = "noqa: DOC502"
198+ raise MDIONotFoundError (err )
199+
188200 def _validate_store (self , storage_options : dict [str , str ] | None ) -> None :
189201 """Method to validate the provided store."""
190202 if storage_options is None :
@@ -317,7 +329,8 @@ def shape(self) -> tuple[int, ...]:
317329 def shape (self , value : tuple [int , ...]) -> None :
318330 """Validate and set shape of dataset."""
319331 if not isinstance (value , tuple ):
320- raise AttributeError ("Array shape needs to be a tuple" )
332+ err = "Array shape needs to be a tuple"
333+ raise AttributeError (err )
321334 self ._shape = value
322335
323336 @property
@@ -329,7 +342,8 @@ def trace_count(self) -> int:
329342 def trace_count (self , value : int ) -> None :
330343 """Validate and set trace count for seismic MDIO."""
331344 if not isinstance (value , int ):
332- raise AttributeError ("Live trace count needs to be an integer" )
345+ err = "Live trace count needs to be an integer"
346+ raise AttributeError (err )
333347 self ._trace_count = value
334348
335349 @property
@@ -341,7 +355,8 @@ def text_header(self) -> list:
341355 def text_header (self , value : list ) -> None :
342356 """Validate and set seismic text header."""
343357 if not isinstance (value , list ):
344- raise AttributeError ("Text header must be a list of str with 40 elements" )
358+ err = "Text header must be a list of str with 40 elements"
359+ raise AttributeError (err )
345360 self ._text_header = value
346361
347362 @property
@@ -353,7 +368,8 @@ def binary_header(self) -> dict:
353368 def binary_header (self , value : dict ) -> None :
354369 """Validate and set seismic binary header metadata."""
355370 if not isinstance (value , dict ):
356- raise AttributeError ("Binary header has to be a dictionary type collection" )
371+ err = "Binary header has to be a dictionary type collection"
372+ raise AttributeError (err )
357373 self ._binary_header = value
358374
359375 @property
@@ -486,8 +502,9 @@ def coord_to_index(
486502 ndim_expect = self .grid .ndim if dimensions is None else len (dimensions )
487503
488504 if len (queries ) != ndim_expect :
505+ err = "Coordinate queries not the same size as n_dimensions"
489506 raise ShapeError (
490- "Coordinate queries not the same size as n_dimensions" ,
507+ err ,
491508 ("# Coord Dims" , "# Dimensions" ),
492509 (len (queries ), ndim_expect ),
493510 )
@@ -558,6 +575,8 @@ def copy( # noqa: PLR0913
558575class MDIOReader (MDIOAccessor ):
559576 """Read-only accessor for MDIO files.
560577
578+ Initialized with `r` permission.
579+
561580 For detailed documentation see MDIOAccessor.
562581
563582 Args:
@@ -596,8 +615,7 @@ def __init__( # noqa: PLR0913
596615 backend : str = "zarr" ,
597616 memory_cache_size : int = 0 ,
598617 disk_cache : bool = False ,
599- ): # TODO: Disabled all caching by default, sometimes causes performance issues
600- """Initialize super class with `r` permission."""
618+ ): # TODO(anyone): Disabled all caching by default, sometimes causes performance issues
601619 super ().__init__ (
602620 mdio_path_or_buffer = mdio_path_or_buffer ,
603621 mode = "r" ,
@@ -614,6 +632,8 @@ def __init__( # noqa: PLR0913
614632class MDIOWriter (MDIOAccessor ):
615633 """Writable accessor for MDIO files.
616634
635+ Initialized with `r+` permission.
636+
617637 For detailed documentation see MDIOAccessor.
618638
619639 Args:
@@ -652,8 +672,7 @@ def __init__( # noqa: PLR0913
652672 backend : str = "zarr" ,
653673 memory_cache_size : int = 0 ,
654674 disk_cache : bool = False ,
655- ): # TODO: Disabled all caching by default, sometimes causes performance issues
656- """Initialize super class with `r+` permission."""
675+ ): # TODO(anyone): Disabled all caching by default, sometimes causes performance issues
657676 super ().__init__ (
658677 mdio_path_or_buffer = mdio_path_or_buffer ,
659678 mode = "r+" ,
0 commit comments