netutils icon indicating copy to clipboard operation
netutils copied to clipboard

Clarify None handling for configuration parsing

Open Kircheneer opened this issue 3 years ago • 3 comments

BaseSpaceConfigParser.build_config_relationship is using multiple ._build_$something methods that currently return an Optional[str]. It is not clear what happens, if one of those actually returns None. We should decide on whether we want to raise an exception in those specific methods or pass the None up the chain and handle it there. In any case, it needs to be handled to get rid of all the # type: ignore comments.

Originally posted by @Kircheneer in https://github.com/networktocode/netutils/pull/123#discussion_r907084287

Kircheneer avatar Jun 29 '22 14:06 Kircheneer

Also applicable to NokiaConfigParser._get_section_title

Kircheneer avatar Jun 29 '22 14:06 Kircheneer

@jmcgill298 any chance you can take a look?

itdependsnetworks avatar Jun 29 '22 19:06 itdependsnetworks

The references to _build_banner all store the value as a variable, and the docstrings document expected Returns: https://github.com/networktocode/netutils/blob/e757bfe84c3e9fce438fa35a737a9c1c9fad4b70/netutils/config/parser.py#L187-L189 (and replicated in other implementations)

The references to _build_nested_config all store the value as a variable, and the docstrings document expected Returns: https://github.com/networktocode/netutils/blob/e757bfe84c3e9fce438fa35a737a9c1c9fad4b70/netutils/config/parser.py#L222-L224

The references to _build_multiline_config do not store it as a variable, so that method should remove returns and always return None.

The reference to _build_multiline_single_configuration_line does not store it as a variable, so that method should remove returns and always return None.

I suspect that the last two methods had a return to simplify writing test cases

jmcgill298 avatar Jul 01 '22 14:07 jmcgill298