Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make NoDefaultSpecified and no_default_specified private #1380

Merged
merged 3 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Traits CHANGELOG
================

Upcoming release X.Y.Z
----------------------

Removals
~~~~~~~~
* Make ``NoDefaultSpecified`` private and remove it from the public API.(#1380)


Release 6.1.1
-------------

Expand Down
2 changes: 0 additions & 2 deletions docs/source/traits_api_reference/trait_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
Classes
-------

.. autoclass:: NoDefaultSpecified

.. autoclass:: TraitType

Private Functions
Expand Down
5 changes: 0 additions & 5 deletions traits-stubs/traits-stubs/trait_type.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ from .base_trait_handler import BaseTraitHandler as BaseTraitHandler

trait_types: Dict[str, int]


class NoDefaultSpecified:
...


_Accepts = TypeVar('_Accepts')

_Stores = TypeVar('_Stores')
Expand Down
48 changes: 48 additions & 0 deletions traits/tests/test_readonly.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# (C) Copyright 2005-2021 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

"""
Tests for the ReadOnly trait type.

"""
import unittest

from traits.api import (
HasTraits,
ReadOnly,
TraitError,
)


class ObjectWithReadOnlyText(HasTraits):
""" A dummy object that set the readonly trait in __init__

There exists such usage in TraitsUI.
"""

text = ReadOnly()

def __init__(self, text, **traits):
self.text = text
super(ObjectWithReadOnlyText, self).__init__(**traits)


class TestReadOnlyTrait(unittest.TestCase):
""" Test ReadOnly TraitType. """

def test_set_readonly_trait_in_init(self):

obj = ObjectWithReadOnlyText(text="ABC")
self.assertEqual(obj.text, "ABC")

with self.assertRaises(TraitError):
obj.text = "XYZ"

self.assertEqual(obj.text, "ABC")
12 changes: 6 additions & 6 deletions traits/trait_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ def _read_only(object, name, value):


# Create a singleton object for use in the TraitType constructor:
class NoDefaultSpecified(object):
class _NoDefaultSpecified(object):
pass


no_default_specified = NoDefaultSpecified()
_no_default_specified = _NoDefaultSpecified()


class TraitType(BaseTraitHandler):
Expand Down Expand Up @@ -173,7 +173,7 @@ class TraitType(BaseTraitHandler):
#: The metadata for the trait.
metadata = {}

def __init__(self, default_value=no_default_specified, **metadata):
def __init__(self, default_value=_no_default_specified, **metadata):
""" TraitType initializer

This is the only method normally called directly by client code.
Expand All @@ -183,7 +183,7 @@ def __init__(self, default_value=no_default_specified, **metadata):
Override this method whenever a different method signature or a
validated default value is needed.
"""
if default_value is not no_default_specified:
if default_value is not _no_default_specified:
self.default_value = default_value

if len(metadata) > 0:
Expand Down Expand Up @@ -257,7 +257,7 @@ def get_default_value(self):

return (dvt, dv)

def clone(self, default_value=no_default_specified, **metadata):
def clone(self, default_value=_no_default_specified, **metadata):
""" Copy, optionally modifying default value and metadata.

Clones the contents of this object into a new instance of the same
Expand Down Expand Up @@ -294,7 +294,7 @@ def clone(self, default_value=no_default_specified, **metadata):

new._metadata.update(metadata)

if default_value is not no_default_specified:
if default_value is not _no_default_specified:
new.default_value = default_value
if self.validate is not None:
try:
Expand Down