Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review comments and minor simplification in code
  • Loading branch information
Ivan Levkivskyi
Ivan Levkivskyi committed May 17, 2018
commit a78dfc1a8ac11d6fe1f4592e1e7a7ac54a08bb24
8 changes: 7 additions & 1 deletion Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ def test_union_object(self):
u1 = Union[int, object]
u2 = Union[object, int]
self.assertEqual(u1, u2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also assert that it isn't object?

self.assertNotEqual(u1, object)
self.assertNotEqual(u2, object)

def test_unordered(self):
u1 = Union[int, float]
Expand All @@ -268,7 +270,9 @@ def test_single_class_disappears(self):

def test_base_class_kept(self):
u = Union[Employee, Manager]
self.assertIsNot(u, Employee)
self.assertNotEqual(u, Employee)
self.assertIn(Employee, u.__args__)
self.assertIn(Manager, u.__args__)

def test_union_union(self):
u = Union[int, float]
Expand Down Expand Up @@ -312,6 +316,8 @@ def test_cannot_instantiate(self):
def test_union_generalization(self):
self.assertFalse(Union[str, typing.Iterable[int]] == str)
self.assertFalse(Union[str, typing.Iterable[int]] == typing.Iterable[int])
self.assertIn(str, Union[str, typing.Iterable[int]].__args__)
self.assertIn(typing.Iterable[int], Union[str, typing.Iterable[int]].__args__)

def test_union_compare_other(self):
self.assertNotEqual(Union, object)
Expand Down
5 changes: 2 additions & 3 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _check_generic(cls, parameters):


def _remove_dups_flatten(parameters):
"""An internal helper for Union creation and substitution: flatten Union's
"""An internal helper for Union creation and substitution: flatten Unions
among parameters, then remove duplicates.
"""
# Flatten out Union[Union[...], ...].
Expand All @@ -224,8 +224,7 @@ def _remove_dups_flatten(parameters):
all_params.remove(t)
params = new_params
assert not all_params, all_params
all_params = set(params)
return tuple(t for t in params if t in all_params)
return tuple(params)


_cleanups = []
Expand Down