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

Deprecate acceptance of lists by Tuple traits #1627

Merged
merged 2 commits into from
Apr 4, 2022

Conversation

mdickinson
Copy link
Member

@mdickinson mdickinson commented Apr 1, 2022

This PR changes the Tuple trait type so that it only ever accepts instances of type tuple. Previously, the argument-less trait type Tuple() would accept (and coerce) list instances in addition to tuple instances, while with arguments (e.g., Tuple(Int(), Int()), only tuples would be accepted.

Work towards #1626, but this PR doesn't change the behaviour of the BaseTuple trait type at all.

Checklist

  • Tests
  • Update API reference (docs/source/traits_api_reference) N/A
  • Update User manual (docs/source/traits_user_manual) N/A
  • Update type annotation hints in traits-stubs N/A

@@ -73,3 +73,22 @@ class A(HasTraits):
b = A()
self.assertEqual(a.foo, (0, ("", 0)))
self.assertIs(a.foo, b.foo)

def test_lists_not_accepted(self):
Copy link
Member Author

Choose a reason for hiding this comment

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

This is just an additional test for existing behaviour that isn't changed by this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth adding the same tests for BaseTuple as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not just yet - I'm deliberately avoiding changing the behaviour of BaseTuple at all in this PR (at least partly because we have other BaseTuple subclasses). I do plan a followup PR at some point for BaseTuple.

Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

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

LGTM with two minor comments

traits/trait_types.py Outdated Show resolved Hide resolved
@@ -73,3 +73,22 @@ class A(HasTraits):
b = A()
self.assertEqual(a.foo, (0, ("", 0)))
self.assertIs(a.foo, b.foo)

def test_lists_not_accepted(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth adding the same tests for BaseTuple as well?

Co-authored-by: Poruri Sai Rahul <rporuri@enthought.com>
@mdickinson mdickinson merged commit d1949c6 into main Apr 4, 2022
@mdickinson mdickinson deleted the deprecate-base-tuple-accepts-list branch April 4, 2022 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants