Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: mypy stub for ConfigObj #184

Open
Vykstorm opened this issue May 21, 2019 · 4 comments
Open

Suggestion: mypy stub for ConfigObj #184

Vykstorm opened this issue May 21, 2019 · 4 comments
Milestone

Comments

@Vykstorm
Copy link

Vykstorm commented May 21, 2019

Hello. I just wanted to suggest adding a 'stub' for this library for static typing using the library mypy (no need to change code, the stub can go in a separate file).
I have my own version here (incomplete)

For example, here is part of the code related to ConfigObj constructor

from typing import *

infile_type = Union[str, Union[List[str], Tuple[str]], IO[str], Dict[str, Any]]
outfile_type = Union[str, IO[str]]

class ConfigObj(Section):
    def __init__(
        self: Any,
        infile: Optional[infile_type] = None,
        raise_errors: bool = False, list_values: bool = True, create_empty: bool = False,
        file_error: bool = False, interpolation: bool = True, stringify: bool = True,
        configspec: Optional[infile_type] = None,
        indent_type: Optional[str] = None,
        encoding: Optional[str] = None, default_encoding: Optional[str] = None,
        unrepr: bool = False, write_empty_values: bool = False, _inspec: bool = False
        ): ...
@Vykstorm
Copy link
Author

It would be usefull for mypy to infer the types of the values returned by the methods as_bool(), as_int(), ... in the Section class

mypy (not python) will raise an error when executing the next code:

from configobj import ConfigObj

def foo(a : str) -> None:
    pass

config = ConfigObj('example.cnf')
foo(config.as_bool('myval'))
error: Argument 1 to "foo" has incompatible type "bool"; expected "str"

@davetapley
Copy link

I started something to do this: https://github.com/JEFuller/dataclasses-configobj

@robdennis
Copy link
Member

I think this is a good idea and typing support in my IDE is generally an important thing for me as a developer.

I don't think that I'm capable of doing anything with this for 5.1.0, but I hope someone is able to take something like this on

@robdennis robdennis added this to the Someday milestone Jan 8, 2023
@jelmer
Copy link
Collaborator

jelmer commented Sep 17, 2024

@Vykstorm / @davetapley can you add this to the repo in a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants