-
-
Notifications
You must be signed in to change notification settings - Fork 386
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
config: make type conversion explicit #357
Conversation
Well, it seems on python 2 I can only use |
Looks like |
The type of a config value depends on the tool that interprets it. Parsing eagerly can lead to a situation where we return a bool instead of a string or a number. Let the user specify the type themselves by passing in a (str, type) tuple into the mapping interface.
The API troubles me. The mapping interface is |
I was trying to stay within the mapping interface, but you're right that it's mixing two different pieces of information. |
Passing a tuple to the mapping interface isn't the best of interfaces, as the key is only the string. Instead, expose `Config.get_bool()` and `Config.get_int()` methods to parse the values as per the git-config rules before returning the appropriate type to the user. The mapping interface itself returns a string.
Changed API to have Would you like me to squash this into one? |
If anything I would remove the mapping interface and implement By the way, I get an error building the documentation:
|
This is what happens when you assume instead of setting up paths correctly. For whatever reason the keyword for method is |
Re dropping mapping: asking for a single value as a string is a very common operation, which corresponds quite well to dictionary access (even if there's some funky logic as to how the key gets hashed), so I'd like to keep it. The other operations exist mostly because the config format has its own rules as to what constitutes a boolean value and integers have their own suffix rules. We could also go the route of providing static functions that expose the parsing, which would get rid of multiple ways of accessing the value itself but still let the user parse with git-config rules, something like Config.parse_int(config['core.deltabasecachelimit']) This would also let the user apply these rules to data that doesn't come directly from the config but which has the same semantics. Come to think of it, we should expose this anyway and then we can think about whether |
Okey. By the way, I guess the config stuff is also a good candidate for cffi. |
Yeah, that's what I was thinking as well. There's a bit of bootstrapping that it needs, but once the remote-cffi PR is merged, I can start working on that. |
The type of a config value depends on the tool that interprets
it. Parsing eagerly can lead to a situation where we return a bool
instead of a string or a number.
Let the user specify the type themselves by passing in a (str, type)
tuple into the mapping interface.