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)