Skip to content

Add type hints to code #4940

@Flamefire

Description

@Flamefire

Python 3 supports type hints for parameters and return values.

They make the code a lot more understandable.

E.g.

def modify_env(old: Dict[str, str], new: Dict[str, str], verbose: bool=True) -> None:

def setvar(key: str, value: str, verbose: bool=True) -> None:

def remove_unwanted_chars(inputstring: str) -> str:

With this you can often skip reading the doc string as the semantic is more clear.

Python 3.9 introduces direct support for indexing types, i.e. dict[str, str] or tuple(str, int, int) but for earlier version you got from typing import Dict, Tuple with the same semantic & syntax just using the uppercase letter

I propose gradually introducing such type hints

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions