Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
fslpy
Commits
5488df08
Commit
5488df08
authored
11 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
A little bit of property type tweaking; list still broken
parent
2c342ace
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/props/properties_types.py
+19
-17
19 additions, 17 deletions
fsl/props/properties_types.py
with
19 additions
and
17 deletions
fsl/props/properties_types.py
+
19
−
17
View file @
5488df08
...
...
@@ -6,10 +6,9 @@
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import
os
import
os.path
as
op
from
collections
import
OrderedDict
import
numbers
import
matplotlib.colors
as
mplcolors
import
matplotlib.cm
as
mplcm
...
...
@@ -30,8 +29,8 @@ class Boolean(props.PropertyBase):
def
validate
(
self
,
instance
,
value
):
props
.
PropertyBase
.
validate
(
self
,
instance
,
value
)
try
:
value
=
bool
(
value
)
except
:
raise
ValueError
(
'
Must be a boolean
'
)
if
not
isinstance
(
value
,
bool
)
:
raise
ValueError
(
'
Must be a boolean
'
)
class
Number
(
props
.
PropertyBase
):
...
...
@@ -68,6 +67,9 @@ class Number(props.PropertyBase):
def
validate
(
self
,
instance
,
value
):
props
.
PropertyBase
.
validate
(
self
,
instance
,
value
)
if
not
isinstance
(
value
,
numbers
.
Number
):
raise
ValueError
(
'
Must be a number
'
)
minval
=
self
.
getConstraint
(
instance
,
'
minval
'
)
maxval
=
self
.
getConstraint
(
instance
,
'
maxval
'
)
...
...
@@ -94,15 +96,16 @@ class Int(Number):
def
validate
(
self
,
instance
,
value
):
try
:
value
=
int
(
value
)
except
:
raise
ValueError
(
'
Must be an integer ({})
'
.
format
(
value
))
Number
.
validate
(
self
,
instance
,
value
)
if
not
isinstance
(
value
,
numbers
.
Integral
):
raise
ValueError
(
'
Must be an integer
'
)
class
Double
(
Number
):
"""
A property which encapsulates a double.
A property which encapsulates a double. TODO Double is a silly name.
Change it to Real.
"""
def
__init__
(
self
,
**
kwargs
):
...
...
@@ -114,12 +117,12 @@ class Double(Number):
def
validate
(
self
,
instance
,
value
):
try
:
value
=
float
(
value
)
except
:
raise
ValueError
(
'
Must be a number ({})
'
.
format
(
value
))
Number
.
validate
(
self
,
instance
,
value
)
if
not
isinstance
(
value
,
numbers
.
Real
):
raise
ValueError
(
'
Must be a floating point number
'
)
class
Percentage
(
Double
):
"""
...
...
@@ -171,11 +174,12 @@ class String(props.PropertyBase):
if
value
is
None
:
return
if
not
isinstance
(
value
,
basestring
):
raise
ValueError
(
'
Must be a string
'
)
minlen
=
self
.
getConstraint
(
instance
,
'
minlen
'
)
maxlen
=
self
.
getConstraint
(
instance
,
'
maxlen
'
)
value
=
str
(
value
)
if
minlen
is
not
None
and
len
(
value
)
<
minlen
:
raise
ValueError
(
'
Must have length at least {}
'
.
format
(
minlen
))
...
...
@@ -233,8 +237,6 @@ class Choice(String):
"""
String
.
validate
(
self
,
instance
,
value
)
value
=
str
(
value
)
if
value
not
in
self
.
choices
:
raise
ValueError
(
'
Invalid choice ({})
'
.
format
(
value
))
...
...
@@ -742,6 +744,6 @@ class ColourMap(props.PropertyBase):
elif
not
isinstance
(
value
,
mplcolors
.
Colormap
):
raise
ValueError
(
'
Invalid ColourMap value:
'
.
format
(
default
.
__class__
.
__name__
))
value
.
__class__
.
__name__
))
props
.
PropertyBase
.
__set__
(
self
,
instance
,
value
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment