Skip to content
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

Release 0.18.0 #49

Merged
merged 3 commits into from Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -2,6 +2,11 @@
CHANGELOG
=========

0.18.0
===============

* SumType variants are attribute-strict #48

0.16.0 - 0.17.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.17'
version = '0.18'
# The full version, including alpha/beta/rc tags.
release = '0.17.0'
release = '0.18.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
6 changes: 3 additions & 3 deletions requirements/test.txt
@@ -1,6 +1,6 @@
-r ./minimal.txt
pytest>=5.0.0,<5.1.0
coverage==4.5.3
pytest>=5.1.1,<5.2.0
coverage>=4.5.4,<4.6.0
pytest-cov>=2.7.1,<2.8
mypy==0.711
mypy==0.720
py-money==0.4.0
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -38,7 +38,7 @@ def requirements(at_path: Path):
# ----------------------------

setup(name='typeit',
version='0.17.0',
version='0.18.0',
description='typeit brings typed data into your project',
long_description=README,
classifiers=[
Expand Down
26 changes: 24 additions & 2 deletions tests/test_sums.py
@@ -1,4 +1,4 @@
from typing import Dict
from typing import Dict, NamedTuple

import pytest
import pickle
Expand Down Expand Up @@ -148,4 +148,26 @@ class VariantB:
'b': True,
}
x = mk_x(data)
assert serialize_x(x) == data
assert serialize_x(x) == data


def test_sumtype_attr_strictness():
class Versioning(SumType):
class V1:
a: int

class V2:
a: int
b: int

class X(NamedTuple):
payload: Versioning

mk_x, serialize_x = (
typeit.type_constructor & typeit.flags.SUM_TYPE_DICT('_version_') ^ X
)

with pytest.raises(typeit.Error):
x = mk_x({'payload': {'_version_': 'v1', 'a': 1, 'b': 1}})

x = mk_x({'payload': {'_version_': 'v2', 'a': 1, 'b': 1}})
1 change: 1 addition & 0 deletions typeit/parser.py
Expand Up @@ -175,6 +175,7 @@ def _maybe_node_for_sum_type(
overrides,
memo
)
node.typ.unknown = 'raise'
variant_nodes.append((variant, node))
sum_node = schema.nodes.SchemaNode(
schema.types.Sum(
Expand Down
9 changes: 6 additions & 3 deletions typeit/utils.py
Expand Up @@ -23,9 +23,12 @@ def is_named_tuple(typ: Type[Any]) -> bool:
def clone_schema_node(node):
""" Clonning the node and reassigning the same children,
because clonning is recursive, but we are only interested
in new version of the outermost schema node, the children nodes
in a new version of the outermost schema node, the children nodes
should be shared to avoid unnecessary duplicates.
"""
new_node = node.clone()
new_node.children = node.children
return new_node
# a list comprehension to place the same nodes into
# a new wrapping list object, so that extending
# the cloned node with new children doesn't affect the original node
new_node.children = [x for x in node.children]
return new_node