Skip to content

Commit

Permalink
Update api module and some docs.
Browse files Browse the repository at this point in the history
Fix #2.
  • Loading branch information
abravalheri committed Oct 18, 2021
1 parent ac99bcf commit 3023e22
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
4 changes: 2 additions & 2 deletions docs/dev-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ new processors for different profiles, as shown in the example bellow.

.. code-block:: python
from ini2toml import Translator
from ini2toml.types import Translator
def activate(translator: Translator):
Expand Down Expand Up @@ -236,7 +236,7 @@ shown in the following example:

.. code-block:: python
from ini2toml import Translator, Profile
from ini2toml.types import Translator, Profile
def activate(translator: Translator):
Expand Down
43 changes: 21 additions & 22 deletions src/ini2toml/api.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
"""API available for general public usage.
"""Public API available for general usage.
The function ``activate`` in each submodule of the :obj:`ini2toml.plugins` package
is also considered part of the public API.
In addition to the classes and functions "exported" by this module, the following are
also part of the public API:
- The public members of the :mod:`~ini2toml.types` module.
- The public members of the :mod:`~ini2toml.errors` module.
- The ``activate`` function in each submodule of the :obj:`~ini2toml.plugins` package
Please notice there might be classes of similar names exported by both ``api`` and
``types``. When this happens, the classes in ``types`` are not concrete implementations,
but instead act as :class:`protocols <typing.Protocol>` (i.e. abstract descriptions
for checking `structural polymorphism`_ during static analysis).
These should be preferred when writing type hints and signatures.
Plugin authors can also rely on the functions exported by
:mod:`~ini2toml.transformations`.
.. _structural polymorphism: https://www.python.org/dev/peps/pep-0544/
"""
from .plugins import ErrorLoadingPlugin
from .translator import (
AlreadyRegisteredAugmentation,
InvalidAugmentationName,
Translator,
UndefinedProfile,
)
from .types import Commented, CommentedKV, CommentedList, Profile
from . import errors, transformations, types
from .translator import Translator

__all__ = [
"Commented",
"CommentedKV",
"CommentedList",
"Translator",
"Profile",
"UndefinedProfile",
"InvalidAugmentationName",
"AlreadyRegisteredAugmentation",
"ErrorLoadingPlugin",
]
__all__ = ["Translator", "errors", "types", "transformations"]
11 changes: 11 additions & 0 deletions src/ini2toml/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ def coerce_bool(value: str) -> bool:


def coerce_scalar(value: str) -> Scalar:
"""Try to convert the given string to a proper "scalar" type (e.g. integer, float,
bool, ...) with an direct TOML equivalent.
If the conversion is unknown or not possible, it will return the same input value
(as string).
.. note:: This function "guesses" the value type based in heuristics and/or regular
expressions, therefore there is no guarantee the output has the same type as
intended by the original author.
.. note:: Currently date/time-related types are not supported.
"""
value = value.strip()
if value.isdecimal():
return int(value)
Expand Down

0 comments on commit 3023e22

Please sign in to comment.