Skip to content

Better typing support #1220

@acampove

Description

@acampove

I think the typing used in this project could be improved. The way it is currently, it causes troubles to users. For example to_container returns a very broad type and the user has to cast the output to make sure the code does not throw errors.

    @staticmethod
    def to_container(
        cfg: Any,
        *,
        resolve: bool = False,
        throw_on_missing: bool = False,
        enum_to_str: bool = False,
        structured_config_mode: SCMode = SCMode.DICT,
    ) -> Union[Dict[DictKeyType, Any], List[Any], None, str, Any]:

Also, I would definitely not make cfg an Any. It must be something, a list, dictionary, something.

Describe the solution you'd like

In cases like this I would use overloads to make sure that the types going in and going out are under control and unambiguous.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions