aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-06-20 16:32:23 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2020-06-20 16:32:23 -0500
commitee78049f1e33bcb9894f43d51e44b079edfab91f (patch)
tree816ae8115bae491c20b087429222d4d57203cc74
parentRemove linting phase (diff)
downloadconfig-file-ee78049f1e33bcb9894f43d51e44b079edfab91f.zip
Add types to base parser and update build badge
-rw-r--r--CHANGELOG.md2
-rw-r--r--README.md4
-rw-r--r--config_file/config_file.py1
-rw-r--r--config_file/parsers/base_parser.py12
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.
diff --git a/README.md b/README.md
index 223f3e7..1af08fc 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
[![Version](https://img.shields.io/pypi/v/config-file)](https://pypi.org/project/config-file/)
[![Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/)
[![Documentation Status](https://readthedocs.org/projects/config-file/badge/?version=latest)](https://config-file.readthedocs.io/en/latest/?badge=latest)
-[![Build Status](https://travis-ci.com/eugenetriguba/config-file.svg?branch=master)](https://travis-ci.com/eugenetriguba/config-file)
+[![Build Status](https://github.com/eugenetriguba/config-file/workflows/Python%20package%20CI/badge.svg?branch=master)](https://github.com/eugenetriguba/config-file/actions/)
[![Codecov](https://codecov.io/gh/eugenetriguba/config-file/graph/badge.svg)](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