Skip to content

Commit

Permalink
Backwards compatibility fix: make PrefixMap._map available (#1578)
Browse files Browse the repository at this point in the history
* Backwards compatibility fix for those subclassing PrefixMap

* Add changelog entry
  • Loading branch information
mdickinson committed Oct 11, 2021
1 parent c6bfd7b commit 3a5ba84
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
Traits CHANGELOG
================

Release 6.3.1
-------------

Released: 2021-10-12

Traits 6.3.1 is a bugfix release, fixing an incompatibility between
Traits 6.3.0 and Mayavi <= 4.7.3.

Fixes
~~~~~

* Make ``PrefixMap._map`` available again, for compatibility with Mayavi.
(#1578)


Release 6.3.0
-------------

Expand Down
9 changes: 9 additions & 0 deletions traits/tests/test_prefix_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,12 @@ class Person(HasTraits):
default_value_callable = reconstituted.default_value()[1]

self.assertEqual(default_value_callable(p), 1)

def test_existence_of__map(self):
# This test can be removed once Mayavi no longer depends on the
# existence of the _map attribute.
# xref: enthought/traits#1577
# xref: enthought/mayavi#1094

prefix_map = PrefixMap({"yes": 1, "yeah": 1, "no": 0, "nah": 0})
self.assertEqual(prefix_map._map["yes"], "yes")
7 changes: 7 additions & 0 deletions traits/trait_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3294,6 +3294,13 @@ def __init__(self, map, *, default_value=None, **metadata):
if not map:
raise ValueError("map must be nonempty")
self.map = map
# Provide backwards compatibility for Mayavi, which currently
# subclasses PrefixMap and depends on the existence of the _map
# attribute. This attribute can be removed as soon as RevPrefixMap in
# Mayavi has been fixed.
# xref: enthought/traits#1577
# xref: enthought/mayavi#1094
self._map = {value: value for value in map}

if default_value is not None:
default_value = self._complete_value(default_value)
Expand Down

0 comments on commit 3a5ba84

Please sign in to comment.