Releases: enthought/traits
Traits 6.4.3
This is a bugfix release that fixes test failures with Sphinx 7.2 and later,
and adds support for Python 3.12.
Fixes
Traits 6.4.2
Traits 6.4.1
This is a bugfix release that fixes wheel builds on Python 3.11 and
fixes some distribution and testing issues with typing stubs.
Fixes
* Update `cibuildwheel` to the latest version so that we get wheels for
Python 3.11. (#1711)
* Rename `requires_numpy_testing` decorator to `requires_numpy_typing`,
and have it check for `numpy.typing`, not `numpy.testing`. (#1710)
* Fix missing `numpy_examples` directory in traits-stubs package data.
(#1709)
Traits 6.4.0
Traits 6.4 is a minor feature release of Traits, which focuses mainly on typing
stub and documentation updates.
Migrating from Traits 6.3
Traits 6.4 should be largely backwards compatible with Traits 6.3, but there
are a couple of things to watch out for.
- Reminder: while the
Either
andTrait
trait types are not yet formally
deprecated, the intention is to eventually deprecate and remove them.
Projects are encouraged to update their code to useUnion
instead. - Similarly, any uses of the
Unicode
trait type in your project should
be replaced withStr
. - Validation of items within a container (e.g.,
foos = List(MyTraitType)
)
now always matches the validation used for the item trait at top level (e.g.,
foo = MyTraitType
). Previously, the validation methods used could differ,
thanks to a bug in the container implementations. For most trait types this
will make no difference, but for theTuple
trait type this change has the
consequence that lists will no longer be accepted as valid forTuple
traits inside list items. See issue #1619 and PR #1625 for more information. - Related to the above: a top-level
Tuple()
trait declaration currently
accepts Pythonlist
objects, while aTuple
declaration with explicit
item types (for exampleTuple(Int(), Int())
) does not. The support for
list
objects in plainTuple()
is deprecated, and will be removed in a
future version of Traits. See PR #1627 for more information.
Detailed PR-by-PR changes
The following people contributed code changes for this release:
- Caio Agiani
- Steve Allen
- Mark Dickinson
- Sai Rahul Poruri
- Corran Webster
Features
ETSConfig
attributes now support deletion. This makes it easier to make
temporary changes toETSConfig
attributes during unit testing. (#1670,
#1686)Complex
trait type validation is now more lenient: any type that
implements__complex__
will be accepted. (#1594)BaseFloat
validation is now more lenient, and matchesFloat
validation:BaseFloat
now also accepts objects whose type has an
__index__
method. (#1595)
Changes
- An
enumerate
alias has been removed fromtraits.trait_base
. In the
unlikely event of code that importsenumerate
fromtraits.trait_base
,
use the built-inenumerate
instead. (#1681) - Fast validation tuples
int_fast_validate
,float_fast_validate
and
complex_fast_validate
have been removed from thetraits.trait_types
module. (#1601)
Fixes
TraitListObject
,TraitDict
object andTraitSetObject
now use the
validate
method of the appropriateCTrait
instances to validate
items, keys and values. Previously the handler'svalidate
method was
used; this gave buggy behaviour in cases where the handler'svalidate
method differed from the actual validation in use. (#1625)- Fix specification of
default_value
that incorrectly disregarded
default_value_type
. (#1631) - Fix incorrect results from
clone_traits
applied toList
,Dict
andSet
traits. (#1624) - The
find_resource
andstore_resource
tests are now skipped
if thepkg_resources
module is not present in the environment. (#1679) - An
ETSConfig
test has been renamed so that it's properly picked up
by the test runner. (#1671) - Fix some
ETSConfig
tests that assume unittest as the test runner. (#1683) - Rename various test-related classes to avoid pytest trying to harvest test
methods from them. (#1684) - Overriding a default for a
List
or other collection trait in a subclass
now works as expected. Previously, the behaviour was unusably buggy. (#1645)
Deprecations
Tuple
traits currently accept Pythonlist
objects in some (but
not all) circumstances. That feature is deprecated, and will be removed
in a future version of Traits. (#1627)
Type stubs
- Add stubs for
Array
,ArrayOrNone
, andCArray
. (#1682) - Fix various stubs for
traits.trait_types
; add stubs for
traits.ctraits
. (#1661) - Fix that
TraitError
stubs weren't exposed attraits.api
level.
(#1658) - Make
Int
andFloat
type stubs more accurate. (#1656) - Fix incorrect type stubs for the
Dict
trait type. (#1655)
Documentation
- Make
ETSConfig
class documentation visible in the API docs. (#1688) - Add copy buttons to code samples in documentation. (#1651, #1653)
- Document
Date
,Datetime
andTime
trait types. (#1641) - Fix some missing mentions of
Set
in notification docs. (#1618) - Document the
'some_trait.-'
pattern foron_trait_change
. (#1592) - Document that
Either
should not be used in new code. (#1699) - Document that
TraitPrefixMap
andTraitPrefixList
are deprecated.
(#1702) - Document that the Trait factory function should not be used in new code.
(#1700) - Miscellaneous minor fixes. (#1583, #1611, #1652, #1680)
Build and continuous integration
- Don't collect traits-stubs tests under pytest. As a result of this
and other fixes, the test suite now passes under pytest. (#1690) - Update
etstool.py
for Python 3.8 support. Python 3.8 is now the
default Python version for builds. (#1694) - Use PySide6 for Python >= 3.8 instead of PySide2 in CI testing. (#1685)
- Add
pyproject.toml
files for both Traits and traits-stubs. (#1689, #1676) - Add Python 3.11 to some workflow runs. (#1600, #1660, #1674)
- Add Python 3.10 to install-from-PyPI workflow. (#1576)
- Allow running the main test workflow manually. (#1607)
- Switch Slack channel used to report GitHub Actions failures. (#1650)
- Exclude
build
directory in flake8 configuration. (#1635) - Re-include NumPy as a test dependency on Python 3.10. (#1593)
Maintenance and refactoring
Traits 6.3.2
Traits 6.3.2 is a bugfix release, fixing an issue with duplicate
notifications from Property
traits using the observe
framework.
Fixes
- Fix that
Property
traits usingobserve
metadata could be fired
twice in subclasses. (#1587)
Traits 6.3.1
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)
Traits 6.3.0
Traits 6.3 is the latest feature release in the Traits 6 series, with several
improvements and fixes over Traits 6.2.
Highlights of this release
- There have been various minor performance improvements to the core
on_trait_change
andobserve
machinery. These may improve
startup time for some Traits-using applications. - The
observe
mini-language now has in-language support for listening
to all traits, using the*
character. - Support for Python 3.10 has been added.
Migration guide
Traits 6.3 is intended to be fully backwards compatible with Traits 6.2, and
most projects should have no difficulties upgrading. However, you may see
some new deprecation warnings for existing code, warning about behaviour
that will be changed in Traits 7.0. There are two particular sets of changes
to look out for:
-
Starting with Traits 7.0, the
Any
trait type will treat a default
value of typelist
ordict
differently. Currently, instances of
list
anddict
are special-cased, and a per-instance copy of the
default is provided to eachHasTraits
instance. In Traits 7.0, this
special-casing will be removed, and the default value will be shared between
all instances. For the 6.3 release of Traits, a deprecation warning is issued
whenever a trait definition of the formAny([1, 2, 3])
orAny({})
is encountered. Users can retain the existing behaviour and suppress the
warning by changing their code to use the newfactory
argument to the
Any
trait type, for example replacing a trait declarationfoo = Any({})
withfoo = Any(factory=dict)
, and a trait declarationfoo = Any([1, 2, 3])
withfoo = Any(factory=list, args=([1, 2, 3],))
. -
Starting with Traits 7.0, the
Date
trait type will no longer accept
datetime
instances by default. Traits 6.3 will issue a deprecation
warning whenever adatetime
instance is assigned as a value for
aDate
trait. The existing behaviour can be preserved and the warning
silenced by usingDate(allow_datetime=True)
; alternatively, you can
useDate(allow_datetime=False)
to adopt the Traits 7.0 behaviour
right now.
Detailed PR-by-PR changes
Over 80 pull requests went into this release. The following people contributed
to the release:
- @0xflotus
- Aaron Ayres
- Kit Choi
- Mark Dickinson
- Chigozie Nri
- Poruri Sai Rahul
- Corran Webster
- John Wiggins
- Peter Zahemszky
Thank you to all who contributed!
Features
- The
observe
mini-language now supports use of"*"
for listening to
all traits on aHasTraits
object. Currently this support is limited to
cases where the"*"
appears in a terminal position. For example,
observe("foo:*")
is supported, butobserve("*:foo")
is not.
(#1496, #1525) - The
Any
trait type now supports afactory
argument (with accompanying
args
andkw
arguments). This can be used to specify a per-instance
default, for example withAny(factory=dict)
. (#1557, #1558) - The
DefaultValue
enumeration has a new memberDefaultValue.disallow
intended to be used for trait types that don't have a meaningful default. For
traits using this default value type, an attempt to retrieve the
corresponding default usingdefault_value_for
will raiseValueError
.
(#1546) - When a method is decorated with an
observe
decorator, the method
signature is now checked, and a warning issued if it doesn't match the
expected signature. This should catch the common error of forgetting to
provide theevent
parameter. (#1529) - In
ETSToolkit
, the"qt"
toolkit name is now supported as a synonym
for"qt4"
. (#1436) - The
Date
,Datetime
andTime
trait types have a new argument
allow_none
. In the future, these trait types will not acceptNone
unlessallow_none=True
is specified. (#1432) - The
Date
trait type has a new argumentallow_datetime
. In the future,
datetime
instances will not be valid values for aDate
trait unless
allow_datetime=True
is specified. (#1429)
Performance
- The
ObserverGraph
instances that result from compiling
ObserverExpression
objects and observe mini-language strings are now
cached. This should speed up creation and instantiation ofHasTraits
subclasses that involve listening for the same pattern in multiple places.
(#1516, #1528) - The equality definition on
ObserverExpression
has been simplified.
(#1517) - The
ObserverExpression
,ObserverGraph
and related
classes now use__slots__
to improve speed and memory use. (#1513, #1515) - The
on_trait_change
method has been sped up by almost a factor of two,
by removing unnecessary internal usage of Traits in the parsing and listener
functionality. (#1490, #1491, #1492, #1493)
Changes
- An invalid static default value in a
PrefixList
orPrefixMap
trait
declaration now raisesValueError
rather thanTraitError
. (#1564) PrefixList
andPrefixMap
no longer cache completions. (#1564)- A failure to parse an
observe
mini-language string now raises
ValueError
rather thanLarkError
. (#1507) - The
NotifierNotFound
exception is now published in
traits.observation.api
. (#1498) - An attempt to access a nonexistent "dunder" attribute (an attribute whose
name starts and ends with "__") on aCTrait
instance will now raise
AttributeError
. Previously, it would returnNone
. (#1469, #1474,
#1477)
Deprecations
- The
Any
trait type currently implicitly makes a per-HasTraits
-instance
copy of the default value if that value is an instance of eitherlist
or
dict
. This behaviour is deprecated, and will be removed in Traits 7.0.
For a per-instance default, use the newfactory
argument toAny
instead. (#1548, #1532) - The
Date
,Datetime
andTime
trait types will no longer accept
None
as a valid trait value in the future. To keep the existing
behaviour, use the newallow_none
keyword argument to these trait types.
(#1444) - The
Date
trait type will no longer acceptdatetime
instances by
default in the future. To keep the existing behaviour, use the new
allow_datetime
keyword argument. (#1441) - The
Symbol
trait type is deprecated. For resolution of a string
representing a package/module/object combination, useimport_symbol
instead. (#1542) - The
MetaHasTraits.add_listener
andMetaHasTraits.remove_listener
methods are deprecated. (#1550) - The
clean_filename
andclean_timestamp
utilities are deprecated. If
you need these utilities in your own project, you're advised to copy the
code directly into your project. (#1527) - The
find_resource
andstore_resource
functions are deprecated. New
code should useimportlib.resources
orimportlib_resources
instead
of either of these functions. (#1501)
Fixes
- Invalid assignments to
PrefixList
andPrefixMap
traits produced
an unnecessarily nested exception. This has been fixed. (#1564) - An
observe
-decorated listener method whose name has the special form
"_traitname_changed"
will no longer be triggered both as as result
of theobserve
decorator and the special naming: it will only be
triggered via theobserve
decorator. (#1560) - The
delegate
parameter was mistyped in the typing stubs for the
Delegate
trait type. This has been fixed. (#1556) - The
Function
andMethod
trait types will no longer fail when
arguments are passed. Note that these trait types are already deprecated, and
should not be used in new code. (#1543) - Inner traits of a
Union
trait are now validated properly. Previously, in
trait declarations likefoo = Union(List(Int), Str)
, the list entries
would not be validated. (#1522, #1534) - Traits with a dynamic default that appear as inner traits of a
Tuple
trait are now validated properly. (#1521) - A potential race condition in
ListenerHandler
has been fixed. The
race condition is hard to exercise and has not been witnessed in the wild.
(#1495) - Use of
add_class_trait
to add aList
trait was broken in the presence
of subclasses. This has been fixed. (#1461) - A use of the (deprecated)
distutils
library has been replaced with
sysconfig
. (#1452) - Dynamic default handing has been fixed in the
_instance_handler_factory
used by the TraitsUITableEditor
. (#1446, #1450) - The trait descriptions (the "info" text) for the
File
andDirectory
traits have been fixed to avoid giving a misleading error message when
exists=True
. (#1440) - Clones of
BaseInstance
traits didn't correctly respect theallow_none
parameter. This is now fixed. (#1433) - An outdated reference to the "pyglet" Kiva backend has been removed. (#1431)
Documentation
- Brief installation docs have been added. (#1559)
- Occurrences of
Any(some_list)
in docs have been replaced. (#1547) - The documentation for
sync_trait
has been updated to note that it only
synchronises items forList
traits, not forDict
andSet
traits.
(#1519) - A configuration file for Read the Docs has been added. (#1478)
- A
DeprecationWarning
arising from an unnecessary override of the
add_content
method in theTraitDocumenter
has been fixed. (#1475) - The Sphinx version was temporarily pinned to avoid build failures arising
from bugs in Sphinx 4.0.1. That pin has since been reverted.
(#1471, #1462) - Various docstring fixes have been applied. (#1468, #1465)
- Various typo fixes have been applied. (#1458, #1442)
- References to
HasTraits.set
have been rep...
Traits 6.2.0
Traits 6.2 is the latest feature release in the Traits 6 series, with several
improvements and fixes over Traits 6.1.
Highlights of this release
- The Traits examples are now distributed as part of the Traits egg, and
are contributed to theetsdemo
application. (The latter can be
installed from PyPI withpip install etsdemo
.) - Performance of the
observe
framework has been significantly improved. - It's no longer necessary to specify a trait comparison mode of
ComparisonMode.identity
when usingobserve
to observe items
in aList
,Dict
orSet
. - Support for Python 3.5 has been dropped.
- When importing from Traits, you should always import from one of the
api
modules (for example,traits.api
,traits.adaptation.api
, etc.) This
recommendation has now been made explicit in the documentation. If you find
something you need that's not available from one of theapi
modules,
please let the Traits developers know.
Detailed PR-by-PR changes
More than 60 PRs went into this release. The following people contributed to
this release:
- Aaron Ayres
- Alexandre Chabot-Leclerc
- Kit Choi
- Mark Dickinson
- Kevin Duff
- Glen Granzow
- Matt Hancock
- Rahul Poruri
- Eric Prestat
- Kuya Takami
- Hugo van Kemenade
- Aditya Vats
- Corran Webster
Features
- The
Property
trait type now supports theobserve
keyword. (#1175,
#1400) - Add
|=
support to TraitDict for Python 3.9 and later. (#1306) - Add casting keyword to numeric array types. (#547)
- The Traits examples are now part of the Traits package, and so are
contributed toetsdemo
. (#1275) - The Traits examples package now includes a beginner's tutorial. (#1061)
Performance
- Parsing of the
observe
string was previously a performance bottleneck.
This has been fixed, by removing some redundant parsing calls and by caching
parsing results. (#1343, #1344, #1345)
Changes
- The
NoDefaultSpecified
constant (used as a default value for
theTraitType
default_value
argument) is now public, made
available fromtraits.api
. (#1384, #1380, #1378) - The deprecation of the
TraitMap
trait type has been reversed, because
there are existing uses ofTraitMap
that are hard to replace.
Nevertheless, it is still not recommended to useTraitMap
in new code.
UseMap
instead. (#1365) - An attempt to use
PrefixList
with an empty list, orPrefixMap
or
Map
with an empty dictionary, now raisesValueError
. As a result,
the default default value (which used to beNone
) is always valid.
(#1351) TraitListEvent
arguments are now keyword only. (#1346)- It's no longer necessary to specify a trait comparison mode of
ComparisonMode.identity
when usingobserve
to observe items
in aList
,Dict
orSet
. (#1165, #1328, #1240)
Deprecations
- The
Function
andMethod
trait types are deprecated. Use
Callable
orInstance
instead. (#1399, #1397) - The
edit
parameter toconfigure_traits
has been deprecated. (#1311) - The
UnittestTools._catch_warnings
function has been deprecated. (#1310) - The use of the
CHECK_INTERFACES
global variable for automated
interface checking has been deprecated. (#1231)
Fixes
- Non-
TraitError
exceptions raised duringTuple
validation are now
propagated. Previously they were converted intoTraitError
. (#1393) - Dynamic
Range
andEnum
traits are now properly validated
when inside a container (for exampleTuple
orList
). Previously
no validation was performed. (#1388, #1392) - Remove the unused module-level constant
traits.has_traits.EmptyList
.
(#1366) - Don't hard-code class names in
__repr__
implementations of
TraitListEvent
,TraitSetEvent
andTraitDictEvent
. (#1335) - Don't notify on empty
update
\ s ofDict
traits. (#1308) - Fix exception raised when assigning a NumPy array to a
List
trait. (#1278) - Fix uses of deprecated
logger.warn
function. (#1283) - Fix a bad
Instance
trait declaration for a private trait in
the_TraitChangeCollector
class. (#1411)
Documentation
- Add "Tutorial" section to the main documentation, based on the
newtraits.examples
tutorial content. (#1374) - Clarify that only the
api
modules should be used for imports. (#1387) - Update copyright header end years. (#1376)
- Update contents of
image_LICENSE.txt
. (#1362) - Remove mentions of the removed functions
adapts
andimplements
from
the examples and tutorial. (#1367) - Move Traits introduction description to
index.rst
. (#1358) - Fix path to Enthought logo when building docset. (#1285)
- Fix the
trait_documenter
extension to be less fragile. (#1247) - Add user manual documentation for the
Instance
trait type. (#1395) - Document that the
List
,Dict
andSet
trait types copy on
assignment. (#1402) - Various other minor improvements, typo fixes, and other documentation fixes.
(#1396, #1383, #1381, #1384, #1292, #1355, #1350, #1319, #1292, #1401)
Cleanup and other maintenance
- Remove dead code. (#1281)
- Update
super
usage to the usual Python 3 argument-less pattern. (#1280) - Remove per-import
# noqa
comments inapi
modules in favour of
per-file ignores in theflake8
configuration. (#1269) - Remove out-of-date and non-functional coverage badge from README. (#1263)
- Rename
_i_observable
module toi_observable
. (#1296) - Refactor and simplify method checks. (#1176)
- Fix typo in optional_dependencies comment. (#1235)
- Use ComparisonMode constants instead of magic numbers. (#1229)
Test suite
- Prevent test_enum failures if traitsui or GUI toolkit are not installed.
(#1349) - Tests that require
pkg_resources
are skipped ifsetuptools
is not
installed. (#1301) - Fix an order-dependency bug in the
test_subclasses_weakref
regression
test. (#1290) - Fix a typo in a test method name. (#1309)
- Various additional or improved tests for existing code.
(#1359, #1336, #1330, #1248, #1225, #1208, #1209)
Build and development workflow changes
- Traits now uses GitHub Actions for continuous integration. The Travis CI
and Appveyor configurations have been removed. (#1296, #1360) - CI runs are no longer based on EDM. (#878)
- New CI run for the core test suite, without any optional dependencies.
(#1314) - Test Python 3.9 in the continuous integration (and drop tests for Python
3.5 and older). (#1326, #1313, , #1303) - Make
traits.examples
into a package. (#1348) - Make examples directories
flake8
-clean. (#1353) - Fix examples packaging nit. (#1363)
- Support
-h
for getting help inetstool.py
. (#1347) - Add
shell
command toetstool.py
. (#1293) - Use the
flake8_ets
package in place of the localcopyright_header
package.
Thecopyright_header
package has been removed. (#1341) - Add script
check_observe_timing.py
to benchmark performance of
observe
to compare withon_trait_change
. (#1331) - Correct the minimum Sphinx version in README. (#1216, #1320)
- Restrict Sphinx version to avoid buggy versions. (#1276)
- Make
mypy
an optional dependency. (#1289) - Speed up CI builds for Travis and Appveyor by caching the
pip
directory
(now redundant). (#1241) - Add automated wheel and sdist building for Traits releases. (#1404, #1291)
- Add cron-job workflow to regularly test install of the latest releases
from PyPI. (#1406)
Traits 6.1.1
Traits 6.1.1 is a bugfix release fixing a handful of minor documentation and
test-related issues with the Traits 6.1.0 release. There are no API-breaking
changes in this release. It's recommended that all users of Traits 6.1.0
upgrade to Traits 6.1.1.
Fixes
- Don't mutate global state at import time in a test module. (#1222)
- Standardize and fix copyright years in source files. (#1227, #1198)
- Fix trait-documenter extension tests for Sphinx 3.1. (#1206)
- Fix trait-documenter extension to handle properties correctly. (#1246)
Documentation fixes
- Expand user manual to mention dispatch. (#1195)
- Fix some spelling and grammar errors in the user manual. (#1210)
- Fix description in README to match the one in the setup script. (#1219)
- Update PyPI links and capitalization in README.rst. (#1250)
- Fix user manual mentioning a nonexisting feature in metadata filter. (#1207)
- Fix typo in comment in optional_dependencies. (#1235)
Traits 6.1.0
Released: 2020-06-05
The Traits library is a foundational component of the Enthought Tool Suite. It
provides observable, typed attributes for Python classes, making those classes
suitable for event-driven dataflow programming and for immediate use as models
for graphical user interfaces, like those provided by the TraitsUI library.
Traits 6.1 is the latest feature release in the Traits 6 series, and contains
several major improvements.
Highlights of this release
-
A new
observation
framework for observing traited
attributes and other observable objects has been introduced. This is intended
to provide a full replacement for the existingon_trait_change
mechanism, and aims to fix a number of fundamental flaws and limitations of
that mechanism. See theobserve-notification
section of
the user manual for an introduction to this framework. -
New
TraitList
,TraitDict
andTraitSet
classes have been added,
subclassing Python's built-inlist
,dict
and
set
(respectively). Instances of these classes are observable
objects in their own right, and it's possible to attach observers to them
directly. These classes were primarily introduced to support the new
observation framework, and are not expected to be used directly. The API for
these objects and their notification system is provisional, and may change in
a future Traits release. -
A new
Union
trait type has been added. This is intended as a
simpler replacement for the existingEither
trait type, which
will eventually be deprecated. -
New
PrefixList
,PrefixMap
andMap
trait types
have been added. These replace the existingTraitPrefixList
,
TraitPrefixMap
andTraitMap
subclasses of
TraitHandler
, which are deprecated. -
Typing stubs for the Traits library have been added in a
traits-stubs
package, which will be released separately to PyPI. This
should help support Traits-using projects that want to make use of type
annotations and type checkers likemypy
.
Notes on upgrading
As far as possible, Traits 6.1 is backwards compatible with Traits 6.0.
However, there are a few things to be aware of when upgrading.
-
Traits 6.1 is not compatible with TraitsUI versions older than TraitsUI 7.0.
A combination of Traits 6.1 or later with TraitsUI 6.x or earlier will fail
to properly recogniseView
class variables as
TraitsUI views, and an error will be raised if you attempt to create a
TraitsUI view. -
Traits now does no logging configuration at all, leaving all such
configuration to the application.In more detail: trait notification handlers should not raise exceptions in
normal use, so an exception is logged whenever a trait notification handler
raises. This part of the behaviour has not changed. What has changed is the
way that logged exception is handled under default exception handling.Previously, Traits added a
logging.StreamHandler
to the
top-level"traits"
logger, so that trait notification exceptions would
always be visible. Traits also added alogging.NullHandler
to that
logger. Both of those handlers have now been removed. We now rely on
Python's "handler of last resort", which will continue to make notification
exceptions to the user visible in the absence of any application-level
log configuration. -
When listening for changes to the items of a
List
trait, an index
or slice set operation no longer performs an equality check between the
replaced elements and the replacement elements when deciding whether to issue
a notification; instead, a notification is always issued if at least one
element was replaced. For example, consider the following class:class Selection(HasTraits): indices = List(Int) @on_trait_change("indices_items") def report_change(self, event): print("Indices changed: ", event)
When replacing the
8
with the same integer, we get this behavior:>>> selection = Selection(indices=[2, 5, 8]) >>> selection.indices[2] = 8 Indices changed: TraitListEvent(index=2, removed=[8], added=[8])
Previously, no notification would have been issued.
-
The
Color
,RGBColor
andFont
trait factories
have moved to TraitsUI, and should be imported from there rather than from
Traits. For backwards compatibility, the factories are still
available in Traits, but they are deprecated and will eventually
be removed. -
As a reminder, the
Unicode
andLong
trait types are
deprecated since Traits 6.0. Please replace uses withStr
and
Int
respectively. To avoid excessive noise in Traits-using
projects, Traits does not yet issue deprecation warnings for existing uses of
Unicode
andLong
. Those warnings will be introduced in a
future Traits release, prior to the removal of these trait types.
Pending deprecations
In addition to the deprecations listed in the changelog below, some parts of
the Traits library are not yet formally deprecated, but are likely to be
deprecated before Traits 7.0. Users should be aware of the following possible
future changes:
-
The
Either
trait type will eventually be deprecated. Where
possible, useUnion
instead. When replacing uses of
Either
withUnion
, note that there are some significant
API and behavioral differences between the two trait types, particularly with
respect to handling of defaults. See the user manual for
more details. -
The
trait_modified
event trait that's present on allHasTraits
subclasses will eventually be removed. Users should not rely on it being
present in an object'sclass_traits
dictionary. -
Trait names starting with
trait
,traits
,_trait
or
_traits
may become reserved for use by ETS at some point in the future.
Avoid using these names for your own traits.
Detailed PR-by-PR changes
More than 160 PRs went into this release. The following people contributed
code changes for this release:
- Ieva Cernyte
- Kit Yan Choi
- Maxime Costalonga
- Mark Dickinson
- Matt Hancock
- Midhun Madhusoodanan
- Shoeb Mohammed
- Franklin Ventura
- Corran Webster
Features
- Add
os.PathLike
support forDirectory
traits. (#867) - Add
Union
trait type. (#779, #1103, #1107, #1116, #1115) - Add
PrefixList
trait type. (#871, #1142, #1144, #1147) - Add
allow_none
flag forCallable
trait. (#885) - Add support for type annotation. (#904, #1064)
- Allow mutable values in
Constant
trait. (#929) - Add
Map
andPrefixMap
trait types. (#886, #953, #956, #970, #1139,
#1189) - Add
TraitList
as the base list object that can perform validation
and emit change notifications. (#912, #981, #984, #989, #999, #1003, #1011,
#1026, #1009, #1040, #1172, #1173) - Add
TraitDict
as the base dict object that can perform validation and
emit change notifications. (#913) - Add
TraitSet
as the base set object that can perform validation and
emit change notifications. (#922, #1043) - Implement
observe
to supersedeon_trait_change
for observing trait
changes. (#976, #1000, #1007, #1065, #1023, #1066, #1070, #1069, #1067,
#1080, #1082, #1079, #1071, #1072, #1075, #1085, #1089, #1078, #1093, #1086,
#1077, #1095, #1102, #1108, #1110, #1112, #1117, #1118, #1123, #1125, #1126,
#1128, #1129, #1135, #1156)
Changes
- GUI applications using Traits 6.1 will require TraitsUI >= 7.0. (#1134)
TraitSetEvent
andTraitDictEvent
initialization arguments are now
keyword-only. (#1036)TraitListObject
will no longer skip notifications even if mutations
result in content that compares equally to the old values. (#1026)TraitListEvent.index
reported by mutations to a list is now normalized.
(#1009)- The default notification error handler for Traits no longer configures
logging, and the top-levelNullHandler
log handler has been removed.
(#1161)
Fixes
- Allow assigning None to
CTrait.post_setattr
. (#833) - Fix reference count error. (#907)
- Improve
HasTraits
introspection withdir()
. (#927) - Fix the datetime-to-str converters used in
DatetimeEditor
. (#937) - Raise
TraitNotificationError
on trailing comma inon_trait_change
.
(#926) - Fix exception swallowing by Trait attribute access. (#959, #960)
- Allow collections in valid values for
Enum
trait. (#889) - Fix
TraitError
when mutating a list/dict/set inside another container.
(#1018) - Fix setting default values via dynamic default methods or overriding trait in
subclasses for mapped traits, used byMap
,Expression
,PrefixMap
.
(#1091, #1188) - Fix setting default values via dynamic default methods or overriding trait in
subclasses forExpression
andAdaptsTo
. (#1088, #1119, #1152)
Deprecations
traits.testing.nose_tools
is deprecated. (#880)SingletonHasTraits
,SingletonHasStrictTraits
and
SingletonHasPrivateTraits
are deprecated. (#887)TraitMap
is deprecated, useMap
instead. (#974)TraitPrefixMap
is deprecated, usePrefixMap
instead. (#974)TraitPrefixList
is deprecated, usePrefixList
. (#974)Color
,RBGColor
andFont
are now deprecated. Use the ones from
TraitsUI instead. (#1022)
Removals
traits_super
is removed. (#1015)
Documentation
- Add details on creating custom trait properties. (#387)
- Cross reference special handler signatures for listening to nested attributes
in list and dict. (#894) - Replace 'Traits 5' with 'Traits 6' in the documentation. (#903)
- Use major.minor version in documentation. (#1124)
- Add initial documentation on Traits internals. (#958)
- Fix example class
OddInt
. (#973) - Add Dos and Donts for writing change handle...