Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Michiel Cottaar
fslpy
Commits
61001d8f
Commit
61001d8f
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Typedict tokenifyKey method made public, and len method added.
parent
f863e667
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fsl/utils/typedict.py
+31
-11
31 additions, 11 deletions
fsl/utils/typedict.py
tests/test_importall.py
+25
-0
25 additions, 0 deletions
tests/test_importall.py
with
56 additions
and
11 deletions
fsl/utils/typedict.py
+
31
−
11
View file @
61001d8f
...
...
@@ -127,7 +127,9 @@ class TypeDict(object):
The ``TypeDict`` is a custom dictionary which allows classes or class
instances to be used as keys for value lookups, but internally transforms
any class/instance keys into strings. Tuple keys are supported. Value
assignment with class/instance keys is not supported.
assignment with class/instance keys is not supported. All keys are
transformed via the :meth:`tokenifyKey` method before being internally
used and/or stored.
If a class/instance is passed in as a key, and there is no value
associated with that class, a search is performed on all of the base
...
...
@@ -150,17 +152,35 @@ class TypeDict(object):
self
[
k
]
=
v
def
__str__
(
self
):
return
self
.
__dict
.
__str__
()
def
__repr__
(
self
):
return
self
.
__dict
.
__repr__
()
def
keys
(
self
):
return
self
.
__dict
.
keys
()
def
values
(
self
):
return
self
.
__dict
.
values
()
def
items
(
self
):
return
self
.
__dict
.
items
()
def
__str__
(
self
):
return
self
.
__dict
.
__str__
()
def
__repr__
(
self
):
return
self
.
__dict
.
__repr__
()
def
__len__
(
self
):
return
len
(
self
.
__dict
)
def
keys
(
self
):
return
self
.
__dict
.
keys
()
def
values
(
self
):
return
self
.
__dict
.
values
()
def
items
(
self
):
return
self
.
__dict
.
items
()
def
__setitem__
(
self
,
key
,
value
):
self
.
__dict
[
self
.
__
tokenifyKey
(
key
)]
=
value
self
.
__dict
[
self
.
tokenifyKey
(
key
)]
=
value
def
__
tokenifyKey
(
self
,
key
):
def
tokenifyKey
(
self
,
key
):
"""
Turns a dictionary key, which may have been specified as a
string, or a combination of strings and types, into a tuple.
"""
...
...
@@ -171,7 +191,7 @@ class TypeDict(object):
if
isinstance
(
key
,
collections
.
Sequence
):
tKeys
=
map
(
self
.
__
tokenifyKey
,
key
)
tKeys
=
map
(
self
.
tokenifyKey
,
key
)
key
=
[]
for
tk
in
tKeys
:
...
...
@@ -206,9 +226,9 @@ class TypeDict(object):
def
__getitem__
(
self
,
key
,
allhits
=
False
,
bykey
=
False
):
origKey
=
key
key
=
self
.
__
tokenifyKey
(
key
)
key
=
self
.
tokenifyKey
(
key
)
bases
=
[]
# Make the code a bit easier by
...
...
This diff is collapsed.
Click to expand it.
tests/test_importall.py
0 → 100644
+
25
−
0
View file @
61001d8f
#!/usr/bin/env python
#
# test_importall.py -
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import
pkgutil
def
test_importall
():
import
fsl
as
fsl
import
fsl.data
as
data
import
fsl.utils
as
utils
import
fsl.scripts
as
scripts
for
_
,
module
,
_
in
pkgutil
.
iter_modules
(
fsl
.
__path__
,
'
fsl.
'
):
__import__
(
module
)
for
_
,
module
,
_
in
pkgutil
.
iter_modules
(
data
.
__path__
,
'
fsl.data.
'
):
__import__
(
module
)
for
_
,
module
,
_
in
pkgutil
.
iter_modules
(
utils
.
__path__
,
'
fsl.utils.
'
):
__import__
(
module
)
for
_
,
module
,
_
in
pkgutil
.
iter_modules
(
scripts
.
__path__
,
'
fsl.scripts.
'
):
__import__
(
module
)
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