| name | clean-code-step-1-api-compatibility-check-mandatory-before-wr |
| description | Sub-skill of clean-code: Step 1: API Compatibility Check (MANDATORY before writing shims) (+2). |
| version | 2.1.0 |
| category | workspace |
| type | reference |
| scripts_exempt | true |
Step 1: API Compatibility Check (MANDATORY before writing shims) (+2)
Step 1: API Compatibility Check (MANDATORY before writing shims)
python3 -c "
import inspect
from old.module import OldClass
from canonical.module import CanonicalClass
print('OLD:', inspect.signature(OldClass.__init__))
print('NEW:', inspect.signature(CanonicalClass.__init__))
"
Checklist before shimming any class:
Step 2: Diverged API — Use Relative Imports, Do NOT Shim
If __init__ signatures differ between old and canonical:
- Do NOT shim the base class — any subclass calling
super().__init__(crs=crs) with the
old kwarg will crash at runtime with TypeError: unexpected keyword argument
- Fix the subclass: change its import to use a local relative import pointing to the
compatible (old) class; shim only the unaffected modules (core/, io/, integrations/)
from digitalmodel.gis.layers.feature_layer import FeatureLayer
from .feature_layer import FeatureLayer
Step 3: Re-export Patch-Target Attributes
Tests that use unittest.mock.patch.object(module, "HAS_X", ...) require HAS_X to exist
as a module-level attribute on the shim module. Shims must re-export these flags:
from digitalmodel.gis.io.geotiff_handler import GeoTIFFHandler
from digitalmodel.gis.io.geotiff_handler import GeoTIFFHandler, HAS_RASTERIO
__all__ = ['GeoTIFFHandler', 'HAS_RASTERIO']