enthought / enthought/traits

Remove default_value_type inference from TraitType subclasses

Open
#1,538 7 comments 0 reactions 0 assignees View on GitHub
type: cleanup
Dominant language
Python
Stars
462
Forks
90
PR merge metrics
No merged PRs in 30d

Description

I've created a series of PRs aimed at bypassing the default_value_type inference code for `TraitType` subclasses. See #1531, #1532, #1536.

Code link: https://github.com/enthought/traits/blob/9f934334668c6c0bf1e2866d6a81417275bbc255/traits/trait_type.py#L34-L52

Rationale:

- making Traits less DWIMmy; in general we want to make the Traits codebase more predictable and reduce the number of corner cases with potentially surprising behaviour
- code complexity: if we can remove the `_infer_default_value_type` function completely then some circular import problems go away - the dependence of that function on `TraitListObject`, `TraitDictObject` and `TraitSetObject` in particular is problematic.
- performance (minor): in the vast majority of cases we go through the inference code even when it's clear from context that the `default_value_type` should be constant. By setting `default_value_type` up front we avoid that code path.

Steps:

- [ ] Make sure that none of the built-in TraitType subclasses are using the default value type inference
- [x] Deal with obviously constant defaults: #1531, and a few more in #1539
- [x] Deal with `Any`: #1532 (this is the only case where list and dict default types are of interest)
- [x] Deal with `BaseClass` and its subclasses: #1536 (some care required in `BaseInstance`)
- [x] Deal with `Constant`: #1540
- [x] Deal with `TraitType` subclasses in tests: #1539
- [x] Determine whether `Symbol` needs changes: it doesn't - Symbol is deprecated in #1542
- [x] Deal with `Event` and `Disallow` (related: #1546)
- [x] Deal with `Delegate` and its subclasses.
- [ ] Loudly deprecate the use of default value type inference for external TraitType subclasses
- [ ] In Traits 7.0, replace `default_value_type = DefaultValue.unspecified` with `default_value_type = DefaultValue.constant` in the `TraitType` base class, and clean up the other classes accordingly.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.