Observable typed attributes for Python classes
This is the final release for Traits 6.0.0. There were no changes (apart from the version number change) between the 6.0.0rc0 release candidate and the final release. See the 6.0.0rc0 release notes for the full list of changes since 5.2.0.
Traits 6.0 is a major update to the Traits package, with a number of backward incompatible changes from its predecessor. Notable changes:
Unicode
and Long
) have
been deprecated in favour of their Python 3 equivalents (for example Str
and Int
).CTrait
and HasTraits
objects is greatly improved.
All of the internal state that was previously hidden within the C extension
is now accessible from Python.Datetime
trait type. The Enum
trait type now supports Python enumerations.
The File
trait type supports path-like objects.More than 150 PRs went into this release. The following people contributed code changes for this release:
Traits 6.0 is a major update to the Traits package, with a number of backward incompatible changes from its predecessor. Notable changes:
Unicode
and Long
) have
been deprecated in favour of their Python 3 equivalents (for example Str
and Int
).CTrait
and HasTraits
objects is greatly improved.
All of the internal state that was previously hidden within the C extension
is now accessible from Python.Datetime
trait type. The Enum
trait type now supports Python enumerations.
The File
trait type supports path-like objects.More than 150 PRs went into this release. The following people contributed code changes for this release:
For the most part, existing code that works with Traits 5.2.0 should continue to work with Traits 6.0.0 without changes. However, there are some potentially breaking changes in Traits 6.0.0, and we recommend applying caution when upgrading.
Here's a guide to dealing with some of the potentially breaking changes.
The Unicode
and CUnicode
trait types are now simply synonyms for
Str
and CStr
. Unicode
and CUnicode
are considered deprecated.
For now, no deprecation warning is issued on use of these deprecated trait
types, but in Traits 6.1.0 and later, warnings may be issued, and in Traits
7.0.0 these trait types may be removed. It's recommended that users update
all uses of Unicode
to Str
and CUnicode
to CStr
to avoid
warnings or errors in the future.
Similarly, Long
and CLong
are now synonyms for Int
and CInt
.
The same recommendations apply as for the Unicode
/ Str
trait types.
Uses of NO_COMPARE
, OBJECT_IDENTITY_COMPARE
and RICH_COMPARE
should be replaced with the appropriate ComparisonMode
enumeration
members.
The validation for a Instance(ISomeInterface)
trait type has changed,
where ISomeInterface
is a subclass of Interface
. Previously, an
assignment to such a trait validated the type of the assigned value against
the interface, method by method. Now an isinstance
check is performed
against the interface instead. Make sure that classes implementing a given
interface have the appropriate provides
decorator.
One notable side-effect of the above change is that plain mock.Mock
instances can no longer be assigned to Instance(ISomeInterface)
traits.
To get around this, use spec=ISomeInterface
when creating your mock
object.
This change does not affect Instance
traits for non-interface classes.
The format of TraitListEvents
has changed: for list events generated from
a slice set or slice delete operation where that slice had a step other
than 1
, the added
and removed
fields of the event had an extra
level of list wrapping (for example, added
might be [[1, 2, 3]]
instead of [1, 2, 3]
). In Traits 6.0, this extra wrapping has been
removed. There may be existing code that special-cased the extra wrapping.
Many classes and functions have moved around within the Traits codebase.
If you have code that imports directly from Traits modules and subpackages
instead of from traits.api
or the other subpackage api
modules, some
of those imports may fail. To avoid potential for ImportError
s, you
should import from traits.api
whenever possible. If you find yourself
needing some piece of Traits functionality that isn't exposed in
traits.api
, and you think it should be, please open an issue on the
Traits bug tracker.
Add new Datetime
trait type. (#737, #814, #813, #815, #848)
Support Python Enums as value sets for the Enum
trait. (#685, #828, #855)
Add Subclass
alias for the Type
trait type. (#739)
Add path-like support for the File
trait. (#736)
Add new ComparisonMode
enumeration type to replace the old
NO_COMPARE
, OBJECT_IDENTITY_COMPARE
and RICH_COMPARE
constants. The old constants are deprecated. (#830, #719, #680)
Add fast validation for Callable
trait type; introduce
new BaseCallable
trait type for subclassing purposes.
(#798, #795, #767)
Add CTrait.comparison_mode
property to allow inspection and
modification of a trait's comparison mode. (#758, #735)
Add as_ctrait
converter function to traits.api
. This function
converts a trait-like object or type to a CTrait
, raising TypeError
for objects that can't be interpreted as a CTrait
. It's intended
for use by users who want to create their own parameterised trait
types.
The as_ctrait
feature comes with, and relies upon, a new informal
interface: objects that can be converted to something of type CTrait
can
provide an zero-argument as_ctrait
method that returns a new CTrait
.
Types can provide an instantiate_and_get_ctrait
method, which when
called with no arguments provides a new CTrait
for that type.
(#783, #794)
Add a new HasTraits._class_traits
method for introspection of an
object's class traits. This parallels the existing
HasTraits._instance_traits
method. This method is intended for use in
debugging. It's not recommended for users to modify the returned dictionary.
(#702)
Add CTrait.set_default_value
method for setting information about the
default of a CTrait
. This provides an alternative to the previous method
of using CTrait.default_value
. The use of CTrait.default_value
to set
(rather than get) default information is deprecated. (#620)
Add new methods HasTraits._trait_notifications_enabled
,
HasTraits._trait_notifications_vetoed
to allow introspection of the
notifications states set by the existing methods
HasTraits._trait_change_notify
and HasTraits._trait_veto_notify
.
(#704)
Add TraitKind
, ValidateTrait
and DefaultValue
Python enumeration
types to replace previous uses of magic integers within the Traits codebase.
(#680, #857)
The various CTrait
internal flags are now exposed to Python as
properties: CTrait.is_property
(read-only), CTrait.modify_delegate
,
CTrait.setattr_original_value
, CTrait.post_setattr_original_value
,
CTrait.is_mapped
, and CTrait.comparison_mode
. (#666, #693)
CTrait
, the py_post_setattr
and py_validate
fields are pickled directly. Previously, callables for those fields were
replaced with a -1
sentinel on pickling. (#780)TraitListEvent
is no longer emitted for a slice deletion which
doesn't change the contents of the list. (For example, del obj.mylist[2:]
on a list that only has 2 elements.) (#740)added
and removed
attributes on a TraitListEvent
are now
always lists containing the added or removed elements. Previously, those
lists were nested inside another list in some cases. (#771)Instance(ISomeInterface)
to use an isinstance
check on
trait set instead of using the dynamic interface checker. (#630)AbstractViewElement
abstract base class, and register
the TraitsUI ViewElement
as implementing it. This paves the way for
removal of Traits UI imports from Traits. (#617)ViewElements
are now computed lazily, instead of at HasTraits
subclass creation time. This removes a traitsui
import from
the trait.has_traits
module. (#614)traits.util.clean_filename
utility now uses a different algorithm,
and should do a better job with accented and Unicode text. (#589)BaseInt
validation now matches Int
validation, and
Range
type checks now match those used in Int
and Float
. (#588)TraitError
raised during validation of a
compound trait will now be propagated. Previously, that exception would
be swallowed. (#581)six
package. (#638)configure_traits
. (#796)traits.testing.optional_dependencies
, make sure traitsui.api
is
available whenever traitsui
is. (#616)TraitInstance
now inherits directly from TraitHandler
instead of
(the now removed) ThisClass
. (#761)ValidateTrait.int_range
. (#805)copy
method override from TraitSetObject
. (#759)TraitListObject.clear
to issue the appropriate items event. (#732)[None]
passed into
List(This(allow_none=False))
. (#734)bytes_editor
and password_editor
bugs, and add tests for
all editor factories. (#660)True
is assigned to a trait of type CInt
, the resulting
value is now 1
. Previously, it was True
. (#647)BaseRange
to accept the same values as Range
. (#583)Range
to accept integer-like objects. (#582)Range
to accept float-like values. (#579)filename
argument to configure_traits
. (#572)ctraits.c
. (#844)NO_COMPARE
, OBJECT_IDENTITY_COMPARE
and RICH_COMPARE
constants are deprecated. Use the corresponding members of the
ComparisonMode
enumeration instead. (#719)Unicode
, CUnicode
, BaseUnicode
and BaseCUnicode
trait
types are deprecated. Use Str
, CStr
, BaseStr
and BaseCStr
instead. (#648)Long
, CLong
, BaseLong
and BaseCLong
trait types are
deprecated. Use Int
, CInt
, BaseInt
and BaseCInt
instead.
(#645, #573)AdaptedTo
trait type is deprecated. Use Supports
instead. (#760)false
, true
, undefined
, ListInt
,
ListFloat
, ListStr
, ListUnicode
, ListComplex
, ListBool
,
ListFunction
, ListMethod
, ListThis
, DictStrAny
,
DictStrStr
, DictStrInt
, DictStrFloat
, DictStrBool
,
DictStrList
. (#627)filename
argument to configure_traits
(for storing
state to or restoring state from pickle files) is deprecated. (#792)TraitTuple
, TraitList
and TraitDict
trait handlers
are deprecated. Use the Tuple
, List
and Dict
trait types instead.
(#770)CTrait.default_value
for setting default value information is
deprecated. Use CTrait.set_default_value
instead. (#620)rich_compare
trait metadata is deprecated. Use the
comparison_mode
metadata instead. (#598)ThisClass
,
TraitClass
, TraitExpression
, TraitCallable
, TraitString
,
TraitRange
, TraitWeakRef
. (#782, #711, #699, #698, #625, #593, #587,
#640)CTrait.rich_compare
has been removed. (#598)cTrait.cast
method has been removed. (#663)TraitValue
and associated machinery have been removed. (#658)Generic
trait type has been removed. (#657)UStr
trait type and HasUniqueStrings
class have been removed.
(#654)str_find
and str_rfind
helper functions have been removed. (#633)_trait_notification_handler
has been removed. (#619)BaseTraitHandler.repr
has been removed. (#599)HasTraits.trait_monitor
was undocumented, untested, and broken, and
has been removed. (#570)TraitInstance
trait handler (not to be confused
with the Instance
trait type) no longer supports adaptation. (#641)DynamicView
and HasDynamicViews
classes have been removed
from Traits and moved to TraitsUI instead. (#609)DictStrLong
has been removed. (#573)traits.ctraits
module. (#826, #824,
#659, #653, #829, #836)TraitHandler
documentation. (#817)flake8
check in both Travis CI and Appveyor runs. (#753, #762)gnureadline
as a development dependency on macOS and Linux. (#607)etstool.py
option to run tests quietly. (#606)This release includes a lot of refactoring and many minor improvements that will primarily benefit those working with the Traits codebase. These changes should not affect user-visible functionality. Here's a summary of the more significant changes.
flake8
clean. (#786, #753, #747, #748, #746,
#595)ctraits.c
has been run through clang-tidy
and clang-format
in
order to bring it closer to PEP 7 style. (#715)traits.editor_factories
module, to help compartmentalize code dependencies on TraitsUI. (#661)TraitDictObject
, TraitListObject
,
TraitSetObject
) have each been moved into their own module, along
with their associated event type. (#677)This is a minor feature release, with various small updates and bugfixes.
The most notable user-facing changes are the deprecation of the Category
class, which is scheduled for removal in Traits 6.0.0, and the removal of the Class
, ListClass
and ListInstance
Trait types, which relate to old-style Python 2 classes.
Summary of changes since the 5.1.2 release:
TraitListEvent.index
is always an integer. (#548)collections.MutableMapping
import. (#530)Category
base class. (#509)setup.py
. (#515)ViewElement
. (#559)unittest
compatible. (#551)AdaptsTo
with Supports
. (#532)Class
trait. (#520)Category
trait. (#510)classmethod
. (#500)NullHandler
. (#518)unittest
to run tests in CI. (#552)etstool.py
. (#550)--editable
option for install
, update
CI commands. (#546)etstool.py
. (#511)This is a bugfix release that fixes an issue with the traits-documenter Sphinx extension. This issue produced invalid reST from Traits with multiline definitions, and could prevent PDF documentation builds from completing successfully.
This is a bugfix release, fixing a regression in Traits 5.1.0 that prevented Traits UI applications working correctly on Python 2.7. (The bug does not affect Python 3.)
_py2to3.str_find
and _py2to3.str_rfind
. (#472)This release reverts a feature introduced into the 5.0.0 release, namely pickleability and deep copying of dynamically added traits (traits added via the add_trait
method). That feature unfortunately introduced some unexpected breakage, so has had to be reverted for the time being.
The release also includes various other minor features and fixes.
FileEditor
behavior for a File
trait based on
whether exists=True
is specified for that trait. (#451, #467)traits.api.python_version
has been removed. Internals have been
refactored to use six.PY2
in preference to sys.version_info
.
(#449)mock
library on Python 3; use
unittest.mock
instead. (#446)RuntimeError: empty_like method already has a docstring
) with the newest version of NumPy.
(#443)traits._version.git_revision
now gives the full commit hash (for local
builds) instead of an abbreviated 7 hex-digit version. (#453)README.txt
to README.rst
, so that GitHub renders it nicely.__main__
blocks
for unit tests. Remove imports of unittest
from unittest_tools
.
(#448, #446)This major release accumulates more than an year's worth of improvements, changes and bug fixes to the code base.
A few highlights of this release are :
traits.protocols
submodule and related utils.HasRequiredTraits
classHasTraits
subclassesSee the changelog for the complete list of changes included in this release.
This is an incremental release over 4.5, accumulating over a year's worth of bugfixes and small improvements to the code.
Highlights of this release include: