Skip to content

Commit

Permalink
update docs, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Avanov committed Apr 10, 2020
1 parent e452f29 commit ee58c1f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -2,6 +2,12 @@
CHANGELOG
=========

0.21.0
===============

* Support for global attribute name overrides with ``typeit.flags.GLOBAL_NAME_OVERRIDE``


0.20.0
===============

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Expand Up @@ -51,9 +51,9 @@
# built documents.
#
# The short X.Y version.
version = '0.20'
version = '0.21'
# The full version, including alpha/beta/rc tags.
release = '0.20.0'
release = '0.21.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
45 changes: 43 additions & 2 deletions docs/quickstart_guide.rst
Expand Up @@ -67,7 +67,7 @@ and rename the whole structure to better indicate the nature of the data:
``serialize_person :: Person -> Dict`` for you.

``type_constructor & overrides`` produces a new type constructor that takes overrides into consideration,
and ``type_constructor ^ Person`` reads as "type constructor applied to the Person structure" and essentially
and ``type_constructor ^ Person`` reads as "type constructor applied on the Person structure" and essentially
is the same as ``type_constructor(Person)``, but doesn't require parentheses around overrides (and extensions):

.. code-block:: python
Expand Down Expand Up @@ -106,7 +106,9 @@ Instead of relying on automatic dasherizing of this attribute (for instance, wit
`inflection <https://inflection.readthedocs.io/en/latest/>`_ package), which rarely works
consistently across all possible corner cases, ``typeit`` explicitly
provides you with a reference point in the code, that you can track and refactor with
Intelligent Code Completion tools, should that necessity arise.
Intelligent Code Completion tools, should that necessity arise (but this doesn't meant that
you cannot apply a global rule to override all attribute names,
please refer to the :ref:`Constructor Flags` section of this manual for more details).

You can use the same ``overrides`` object to specify rules for attributes of
any nested types, for instance:
Expand Down Expand Up @@ -305,9 +307,48 @@ And, of course, you can use Sum Types in signatures of your serializable data:
payments = mk_payments(json_ready)
.. _Constructor Flags:

Constructor Flags
-----------------

Constructor flags allow you to define global overrides that affect all structures (toplevel and nested) in a uniform fashion.

``typeit.flags.GLOBAL_NAME_OVERRIDE`` -
useful when you want to globally modify output field names from pythonic `snake_style` to another naming convention
scheme (`camelCase`, `dasherized-names`, etc). Here's a few examples:

.. code-block:: python
import inflection
class FoldedData(NamedTuple):
field_three: str
class Data(NamedTuple):
field_one: str
field_two: FoldedData
constructor, to_serializable = type_constructor & GLOBAL_NAME_OVERRIDE(inflection.camelize) ^ Data
data = Data(field_one='one',
field_two=FoldedData(field_three='three'))
serialized = to_serializable(data)
the `serialized` dictionary will look like

.. code-block:: python
{
'FieldOne': 'one',
'FieldTwo': {
'FieldThree': 'three'
}
}
``typeit.flags.NON_STRICT_PRIMITIVES`` -
disables strict checking of primitive types. With this flag, a type constructor for a structure
with a ``x: int`` attribute annotation would allow input values of ``x`` to be strings that could be parsed
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -38,7 +38,7 @@ def requirements(at_path: Path):
# ----------------------------

setup(name='typeit',
version='0.20.0',
version='0.21.0',
description='typeit brings typed data into your project',
long_description=README,
classifiers=[
Expand Down
4 changes: 4 additions & 0 deletions typeit/combinator/constructor.py
Expand Up @@ -68,6 +68,10 @@ def __and__(self, override: OverrideT) -> '_TypeConstructor':
def __xor__(self, typ: Type[T]) -> TypeTools:
return self.__call__(typ, self.overrides)

# helper aliases for those who doesn't like combinators' syntax
override = __and__
apply_on = __xor__


type_constructor = _TypeConstructor()
TypeConstructor = type_constructor

0 comments on commit ee58c1f

Please sign in to comment.