Description
get_hconfig_view() in constructors.py:55-73 uses an isinstance chain to select the correct view class:
def get_hconfig_view(config: HConfig) -> HConfigViewBase:
driver = config.driver
if isinstance(driver, HConfigDriverAristaEOS):
return HConfigViewAristaEOS(config)
if isinstance(driver, HConfigDriverCiscoIOS):
return HConfigViewCiscoIOS(config)
...
Meanwhile, get_hconfig_driver() in the same file uses the cleaner dict-dispatch pattern:
platform_drivers: dict[Platform, type[HConfigDriverBase]] = {
Platform.ARISTA_EOS: HConfigDriverAristaEOS,
...
}
Proposed Improvement
Refactor get_hconfig_view() to use a dict mapping from driver type to view class, consistent with get_hconfig_driver(). This would:
- Make the code easier to extend (add a dict entry vs. a new
if branch)
- Be consistent with the pattern already established in the same file
- Reduce cyclomatic complexity
Description
get_hconfig_view()inconstructors.py:55-73uses anisinstancechain to select the correct view class:Meanwhile,
get_hconfig_driver()in the same file uses the cleaner dict-dispatch pattern:Proposed Improvement
Refactor
get_hconfig_view()to use a dict mapping from driver type to view class, consistent withget_hconfig_driver(). This would:ifbranch)