diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2020-06-20 16:32:23 -0500 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2020-06-20 16:32:23 -0500 |
| commit | ee78049f1e33bcb9894f43d51e44b079edfab91f (patch) | |
| tree | 816ae8115bae491c20b087429222d4d57203cc74 | |
| parent | Remove linting phase (diff) | |
| download | config-file-ee78049f1e33bcb9894f43d51e44b079edfab91f.zip | |
Add types to base parser and update build badge
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | config_file/config_file.py | 1 | ||||
| -rw-r--r-- | config_file/parsers/base_parser.py | 12 |
4 files changed, 10 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f89271..1e52d9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ Changed - Errors have been moved to `exceptions.py`. - The `get_all`, `set_all`, and `delete_all` optional parameter options in `JsonParser` have been renamed to just `all`. This shouldn't have any effect since `JsonParser` is not intended - to be used directly, and that option is not in `ConfigFile`. + to be used directly, and that option was not in `ConfigFile`. - `path`, `parser`, and `contents` on the `ConfigFile` are now all properties and can only be retrieved. - `restore_original` in `ConfigFile` now raises a `FileNotFoundError` instead of an `OSError` if the original file path does not exist. @@ -6,7 +6,7 @@ [](https://pypi.org/project/config-file/) [](https://pypi.org/project/black/) [](https://config-file.readthedocs.io/en/latest/?badge=latest) -[](https://travis-ci.com/eugenetriguba/config-file) +[](https://github.com/eugenetriguba/config-file/actions/) [](https://codecov.io/gh/eugenetriguba/config-file) ## About Config File @@ -102,7 +102,7 @@ print(config.restore_original()) >>> True ``` -## Documentation +## Documentation Full documentation and API reference is available at https://config-file.readthedocs.io diff --git a/config_file/config_file.py b/config_file/config_file.py index 431521a..6ded72b 100644 --- a/config_file/config_file.py +++ b/config_file/config_file.py @@ -83,6 +83,7 @@ class ConfigFile: parse_types: bool = False, return_type: Any = None, default: Any = None, + all: bool = False, ) -> Any: """ Retrieve the value of a key. diff --git a/config_file/parsers/base_parser.py b/config_file/parsers/base_parser.py index bbdfd91..a1d38d4 100644 --- a/config_file/parsers/base_parser.py +++ b/config_file/parsers/base_parser.py @@ -1,4 +1,5 @@ from abc import ABC, abstractmethod +from typing import Any class BaseParser(ABC): @@ -25,7 +26,7 @@ class BaseParser(ABC): self.parsed_content = self.parse(self.content) @abstractmethod - def get(self, key, parse_types=False): + def get(self, key: str, parse_types: bool = False, all: bool = False): """ Retrieve the value of a key in its native type. This means the string 'true' will be parsed back as the @@ -37,12 +38,12 @@ class BaseParser(ABC): raise NotImplementedError @abstractmethod - def set(self, key, value) -> bool: + def set(self, key: str, value: Any) -> bool: """Sets the value of a key.""" raise NotImplementedError @abstractmethod - def delete(self, section_key) -> bool: + def delete(self, section_key: str) -> bool: """Deletes a key/value pair or entire sections.""" raise NotImplementedError @@ -66,10 +67,9 @@ class BaseParser(ABC): raise NotImplementedError @abstractmethod - def parse(self, file_contents: str): + def parse(self, file_contents: str) -> Any: """ Parse the file_contents into an internal representation - the given parser can work with. It should not return anything - if you're going to be using the super() constructor. + the given parser can work with. """ raise NotImplementedError |