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

Remove unused fast validation tuples #1601

Merged
merged 1 commit into from
Nov 15, 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
3 changes: 0 additions & 3 deletions traits-stubs/traits-stubs/trait_types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ from uuid import UUID as _UUID
from .trait_type import _TraitType

SetTypes: _Any
int_fast_validate: _Any
float_fast_validate: _Any
complex_fast_validate: _Any
bool_fast_validate: _Any


Expand Down
4 changes: 2 additions & 2 deletions traits/tests/test_trait_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ def test_numpy_validators_loaded_if_numpy_present(self):
# If 'numpy' is available, the numpy validators should be loaded,
# even if numpy is imported after traits.
test_script = textwrap.dedent("""
from traits.trait_types import float_fast_validate
from traits.trait_types import bool_fast_validate
import numpy

if numpy.floating in float_fast_validate:
if numpy.bool_ in bool_fast_validate:
print("Success")
else:
print("Failure")
Expand Down
26 changes: 2 additions & 24 deletions traits/trait_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,35 +95,13 @@

try:
# The numpy enhanced definitions:
from numpy import integer, floating, complexfloating, bool_

int_fast_validate = (ValidateTrait.coerce, int, integer)
float_fast_validate = (
ValidateTrait.coerce,
float,
floating,
None,
int,
integer,
)
complex_fast_validate = (
ValidateTrait.coerce,
complex,
complexfloating,
None,
float,
floating,
int,
integer,
)
from numpy import bool_

bool_fast_validate = (ValidateTrait.coerce, bool, None, bool_)
# Tuple or single type suitable for an isinstance check.
_BOOL_TYPES = (bool, bool_)
except ImportError:
# The standard python definitions (without numpy):
int_fast_validate = (ValidateTrait.coerce, int)
float_fast_validate = (ValidateTrait.coerce, float, None, int)
complex_fast_validate = (ValidateTrait.coerce, complex, None, float, int)
bool_fast_validate = (ValidateTrait.coerce, bool)
# Tuple or single type suitable for an isinstance check.
_BOOL_TYPES = bool
Expand Down