From f46a04ccc309a073e0906840b97d49d8383be97a Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 10 Jun 2020 10:29:29 +0100 Subject: [PATCH 1/6] Add a couple of missing imports to api.pyi --- traits-stubs/traits-stubs/api.pyi | 3 +++ .../examples/HasStrictTraits.py | 17 +++++++++++++++++ .../traits_stubs_tests/examples/Interface.py | 15 +++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 traits-stubs/traits_stubs_tests/examples/HasStrictTraits.py create mode 100644 traits-stubs/traits_stubs_tests/examples/Interface.py diff --git a/traits-stubs/traits-stubs/api.pyi b/traits-stubs/traits-stubs/api.pyi index 57b1f1083..52f1d2a6f 100644 --- a/traits-stubs/traits-stubs/api.pyi +++ b/traits-stubs/traits-stubs/api.pyi @@ -20,7 +20,10 @@ from .traits import ( from .has_traits import ( HasTraits as HasTraits, + HasStrictTraits as HasStrictTraits, + Interface as Interface, observe as observe, + provides as provides, ) from .trait_types import ( diff --git a/traits-stubs/traits_stubs_tests/examples/HasStrictTraits.py b/traits-stubs/traits_stubs_tests/examples/HasStrictTraits.py new file mode 100644 index 000000000..ccb19f878 --- /dev/null +++ b/traits-stubs/traits_stubs_tests/examples/HasStrictTraits.py @@ -0,0 +1,17 @@ +from traits.api import Event, HasStrictTraits, observe + + +class Person(HasStrictTraits): + conductor = Event() + + @observe("conductor") + def talk(self, event): + pass + + +def sing(event): + pass + + +person = Person() +person.observe(sing, "conductor") diff --git a/traits-stubs/traits_stubs_tests/examples/Interface.py b/traits-stubs/traits_stubs_tests/examples/Interface.py new file mode 100644 index 000000000..660fb6400 --- /dev/null +++ b/traits-stubs/traits_stubs_tests/examples/Interface.py @@ -0,0 +1,15 @@ +from traits.api import Float, HasTraits, Interface, provides, Str, Tuple + + +class IHasName(Interface): + name = Str() + + +@provides(IHasName) +class NamedColor(HasTraits): + name = Str() + + rgb = Tuple(Float, Float, Float) + + +named_color = NamedColor(name="green", rgb=(0.0, 1.0, 0.0)) From 351c18e57c311c0251bcabb4f6f80a78d654e692 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 10 Jun 2020 10:43:48 +0100 Subject: [PATCH 2/6] Remove mis-spelled stubs file --- traits-stubs/traits-stubs/base_trait_hander.pyi | 13 ------------- traits-stubs/traits-stubs/trait_handler.pyi | 4 ++-- 2 files changed, 2 insertions(+), 15 deletions(-) delete mode 100644 traits-stubs/traits-stubs/base_trait_hander.pyi diff --git a/traits-stubs/traits-stubs/base_trait_hander.pyi b/traits-stubs/traits-stubs/base_trait_hander.pyi deleted file mode 100644 index 3e9b1671f..000000000 --- a/traits-stubs/traits-stubs/base_trait_hander.pyi +++ /dev/null @@ -1,13 +0,0 @@ -# (C) Copyright 2005-2020 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! - - -class BaseTraitHandler(object): - ... diff --git a/traits-stubs/traits-stubs/trait_handler.pyi b/traits-stubs/traits-stubs/trait_handler.pyi index 02b463ccc..d0f24c8b3 100644 --- a/traits-stubs/traits-stubs/trait_handler.pyi +++ b/traits-stubs/traits-stubs/trait_handler.pyi @@ -8,8 +8,8 @@ # # Thanks for using Enthought open source! -from .base_trait_hander import BaseTraitHandler +from .base_trait_handler import BaseTraitHandler class TraitHandler(BaseTraitHandler): - ... \ No newline at end of file + ... From 388cf887fb92eeec76595d0623b4d8235694f9fc Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 10 Jun 2020 10:44:06 +0100 Subject: [PATCH 3/6] Add missing api.pyi stubs for the has_traits module --- traits-stubs/traits-stubs/api.pyi | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/traits-stubs/traits-stubs/api.pyi b/traits-stubs/traits-stubs/api.pyi index 52f1d2a6f..ac7b19679 100644 --- a/traits-stubs/traits-stubs/api.pyi +++ b/traits-stubs/traits-stubs/api.pyi @@ -19,11 +19,27 @@ from .traits import ( ) from .has_traits import ( + ABCHasStrictTraits as ABCHasStrictTraits, + ABCHasTraits as ABCHasTraits, + ABCMetaHasTraits as ABCMetaHasTraits, + AbstractViewElement as AbstractViewElement, HasTraits as HasTraits, HasStrictTraits as HasStrictTraits, + HasPrivateTraits as HasPrivateTraits, + HasRequiredTraits as HasRequiredTraits, Interface as Interface, + SingletonHasTraits as SingletonHasTraits, + SingletonHasStrictTraits as SingletonHasStrictTraits, + SingletonHasPrivateTraits as SingletonHasPrivateTraits, + MetaHasTraits as MetaHasTraits, + Vetoable as Vetoable, + VetoableEvent as VetoableEvent, observe as observe, + on_trait_change as on_trait_change, + cached_property as cached_property, + property_depends_on as property_depends_on, provides as provides, + isinterface as isinterface, ) from .trait_types import ( From 91c8ddc31659734289237c94a6478d35af20004c Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 10 Jun 2020 10:54:25 +0100 Subject: [PATCH 4/6] Add CTrait --- traits-stubs/traits-stubs/api.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/traits-stubs/traits-stubs/api.pyi b/traits-stubs/traits-stubs/api.pyi index ac7b19679..9b0230300 100644 --- a/traits-stubs/traits-stubs/api.pyi +++ b/traits-stubs/traits-stubs/api.pyi @@ -18,6 +18,8 @@ from .traits import ( Trait as Trait ) +from .ctrait import CTrait as CTrait + from .has_traits import ( ABCHasStrictTraits as ABCHasStrictTraits, ABCHasTraits as ABCHasTraits, From ab08eb857ea4ccda3f85d6c6de929dc24efbbcef Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 10 Jun 2020 10:57:08 +0100 Subject: [PATCH 5/6] Add imports for BaseTraitHandler and TraitHandler --- traits-stubs/traits-stubs/api.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/traits-stubs/traits-stubs/api.pyi b/traits-stubs/traits-stubs/api.pyi index 9b0230300..9b59e3a2a 100644 --- a/traits-stubs/traits-stubs/api.pyi +++ b/traits-stubs/traits-stubs/api.pyi @@ -8,7 +8,6 @@ # # Thanks for using Enthought open source! -from .trait_type import TraitType as TraitType from .traits import ( Color as Color, Default as Default, @@ -167,6 +166,9 @@ from .trait_types import ( ValidatedTuple as ValidatedTuple ) +from .base_trait_handler import BaseTraitHandler as BaseTraitHandler +from .trait_handler import TraitHandler as TraitHandler +from .trait_type import TraitType as TraitType from .trait_handlers import ( TraitCoerceType as TraitCoerceType, TraitCastType as TraitCastType, From b605efde775d6528bb96ff705c8ef4f01e27cc4a Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 10 Jun 2020 11:11:04 +0100 Subject: [PATCH 6/6] Add constants --- traits-stubs/traits-stubs/api.pyi | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/traits-stubs/traits-stubs/api.pyi b/traits-stubs/traits-stubs/api.pyi index 9b59e3a2a..833f8bd4b 100644 --- a/traits-stubs/traits-stubs/api.pyi +++ b/traits-stubs/traits-stubs/api.pyi @@ -8,6 +8,16 @@ # # Thanks for using Enthought open source! +from .constants import ( + ComparisonMode as ComparisonMode, + DefaultValue as DefaultValue, + TraitKind as TraitKind, + ValidateTrait as ValidateTrait, + NO_COMPARE as NO_COMPARE, + OBJECT_IDENTITY_COMPARE as OBJECT_IDENTITY_COMPARE, + RICH_COMPARE as RICH_COMPARE, +) + from .traits import ( Color as Color, Default as Default,