Traits

Latest version: v6.4.3

Safety actively analyzes 682441 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 4 of 8

6.3

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 type ``list`` or ``dict`` differently. Currently, instances of
``list`` and ``dict`` are special-cased, and a per-instance copy of the
default is provided to each ``HasTraits`` 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 form ``Any([1, 2, 3])`` or ``Any({})``
is encountered. Users can retain the existing behaviour and suppress the
warning by changing their code to use the new ``factory`` argument to the
``Any`` trait type, for example replacing a trait declaration ``foo =
Any({})`` with ``foo = Any(factory=dict)``, and a trait declaration ``foo =
Any([1, 2, 3])`` with ``foo = 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 a ``datetime`` instance is assigned as a value for
a ``Date`` trait. The existing behaviour can be preserved and the warning
silenced by using ``Date(allow_datetime=True)``; alternatively, you can
use ``Date(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 a ``HasTraits`` object. Currently this support is limited to
cases where the ``"*"`` appears in a terminal position. For example,
``observe("foo:*")`` is supported, but ``observe("*:foo")`` is not.
(1496, 1525)
* The ``Any`` trait type now supports a ``factory`` argument (with accompanying
``args`` and ``kw`` arguments). This can be used to specify a per-instance
default, for example with ``Any(factory=dict)``. (1557, 1558)
* The ``DefaultValue`` enumeration has a new member ``DefaultValue.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 using ``default_value_for`` will raise ``ValueError``.
(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 the ``event`` parameter. (1529)
* In ``ETSToolkit``, the ``"qt"`` toolkit name is now supported as a synonym
for ``"qt4"``. (1436)
* The ``Date``, ``Datetime`` and ``Time`` trait types have a new argument
``allow_none``. In the future, these trait types will not accept ``None``
unless ``allow_none=True`` is specified. (1432)
* The ``Date`` trait type has a new argument ``allow_datetime``. In the future,
``datetime`` instances will not be valid values for a ``Date`` 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 of ``HasTraits``
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`` or ``PrefixMap`` trait
declaration now raises ``ValueError`` rather than ``TraitError``. (1564)
* ``PrefixList`` and ``PrefixMap`` no longer cache completions. (1564)
* A failure to parse an ``observe`` mini-language string now raises
``ValueError`` rather than ``LarkError``. (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 a ``CTrait`` instance will now raise
``AttributeError``. Previously, it would return ``None``. (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 either ``list`` or
``dict``. This behaviour is deprecated, and will be removed in Traits 7.0.
For a per-instance default, use the new ``factory`` argument to ``Any``
instead. (1548, 1532)
* The ``Date``, ``Datetime`` and ``Time`` trait types will no longer accept
``None`` as a valid trait value in the future. To keep the existing
behaviour, use the new ``allow_none`` keyword argument to these trait types.
(1444)
* The ``Date`` trait type will no longer accept ``datetime`` 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, use ``import_symbol``
instead. (1542)
* The ``MetaHasTraits.add_listener`` and ``MetaHasTraits.remove_listener``
methods are deprecated. (1550)
* The ``clean_filename`` and ``clean_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`` and ``store_resource`` functions are deprecated. New
code should use ``importlib.resources`` or ``importlib_resources`` instead
of either of these functions. (1501)


Fixes
~~~~~

* Invalid assignments to ``PrefixList`` and ``PrefixMap`` 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 the ``observe`` decorator *and* the special naming: it will only be
triggered via the ``observe`` decorator. (1560)
* The ``delegate`` parameter was mistyped in the typing stubs for the
``Delegate`` trait type. This has been fixed. (1556)
* The ``Function`` and ``Method`` 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 like ``foo = 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 a ``List`` 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 TraitsUI ``TableEditor``. (1446, 1450)
* The trait descriptions (the "info" text) for the ``File`` and ``Directory``
traits have been fixed to avoid giving a misleading error message when
``exists=True``. (1440)
* Clones of ``BaseInstance`` traits didn't correctly respect the ``allow_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 for ``List`` traits, not for ``Dict`` and ``Set`` 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 the ``TraitDocumenter`` 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 replaced with
``HasTraits.trait_set``. (1451)
* Some issues with the tutorial CSS used in the ETS demo application have been
fixed; the colour scheme has been changed to Enthought colours. (1421,
1419)


Cleanup and refactoring
~~~~~~~~~~~~~~~~~~~~~~~

* All built-in TraitType subclasses now provide the default value type directly
rather than inferring it. (1555, 1536, 1531, 1539, 1532, 1540)
* The ``trait_added`` and ``trait_modified`` traits on ``HasTraits`` now
have proper trait type declarations. (1552)
* Redundant ``unittest.main blocks`` have been removed. (1545)
* Style fixes have been applied to ``trait_types.pyi``. (1523)
* ``ObserverExpression`` and other key observation classes now have more
debug-friendly ``repr`` implementations. (1514)
* The ``observer`` parsing internals have been reworked to make
``ObserverGraph`` the key "compiled" object that the rest of Traits cares
about, rather than ``ObserverExpression``. (1512)
* The grammar and parser for the observe mini-language have been simplified.
(1506)
* Confusion between "any_trait" and "anytrait" in non-user-facing
functions and classes has been cleaned up. (1497)
* Unnecessary ``noqa`` markers have been removed. (1499)
* A use of the ``property`` callable has been replaced with a ``property``
decorator. (1470)
* A bad observe-decorated listener signature in a test has been fixed. (1530)


Build and development workflow
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* Python 3.10 is supported and tested, and wheels are built for Python 3.10.
(1425, 1567, 1569, 1571)
* Wheels are now built for Linux/aarch64. (1567)
* Universal wheels are now built for macOS, to support Apple Silicon. (1567)
* Cron jobs now send failure/success Slack notifications to Enthought's
internal channel. (1481)
* All cron jobs now include a ``workflow_dispatch`` trigger. (1480)
* The main development branch is now called "main" rather than "master".
(1467)
* Automated tests have been added for PyPI wheels. (1417)

6.3.0

-------------

Released: 2021-10-08

6.2

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 the ``etsdemo`` application. (The latter can be
installed from PyPI with ``pip 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 using ``observe`` to observe items
in a ``List``, ``Dict`` or ``Set``.
* 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 the ``api`` 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 the ``observe`` 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 to ``etsdemo``. (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
the ``TraitType`` ``default_value`` argument) is now public, made
available from ``traits.api``. (1384, 1380, 1378)
* The deprecation of the ``TraitMap`` trait type has been reversed, because
there are existing uses of ``TraitMap`` that are hard to replace.
Nevertheless, it is still not recommended to use ``TraitMap`` in new code.
Use ``Map`` instead. (1365)
* An attempt to use ``PrefixList`` with an empty list, or ``PrefixMap`` or
``Map`` with an empty dictionary, now raises ``ValueError``. As a result,
the default default value (which used to be ``None``) 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 using ``observe`` to observe items
in a ``List``, ``Dict`` or ``Set``. (1165, 1328, 1240)


Deprecations
~~~~~~~~~~~~

* The ``Function`` and ``Method`` trait types are deprecated. Use
``Callable`` or ``Instance`` instead. (1399, 1397)
* The ``edit`` parameter to ``configure_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 during ``Tuple`` validation are now
propagated. Previously they were converted into ``TraitError``. (1393)
* Dynamic ``Range`` and ``Enum`` traits are now properly validated
when inside a container (for example ``Tuple`` or ``List``). 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`` and ``TraitDictEvent``. (1335)
* Don't notify on empty ``update``\ s of ``Dict`` 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
new ``traits.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`` and ``implements`` 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`` and ``Set`` 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 in ``api`` modules in favour of
per-file ignores in the ``flake8`` configuration. (1269)
* Remove out-of-date and non-functional coverage badge from README. (1263)
* Rename ``_i_observable`` module to ``i_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 if ``setuptools`` 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 in ``etstool.py``. (1347)
* Add ``shell`` command to ``etstool.py``. (1293)
* Use the ``flake8_ets`` package in place of the local ``copyright_header``
package.
The ``copyright_header`` package has been removed. (1341)
* Add script ``check_observe_timing.py`` to benchmark performance of
``observe`` to compare with ``on_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)

6.2.0

-------------

Released: 2021-01-21

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.

6.1.3

-------------

A bugfix release that fixes a number of issues discovered since the

6.1.2

-------------

A bugfix release that fixes a number of issues discovered since the

Page 4 of 8

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.