Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
ee973b4c
Commit
ee973b4c
authored
5 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
fixed stringify, v2.8.4
parent
7ab46380
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
satella/__init__.py
+1
-1
1 addition, 1 deletion
satella/__init__.py
satella/coding/transforms/__init__.py
+8
-8
8 additions, 8 deletions
satella/coding/transforms/__init__.py
tests/test_coding/test_transforms.py
+3
-0
3 additions, 0 deletions
tests/test_coding/test_transforms.py
with
12 additions
and
9 deletions
satella/__init__.py
+
1
−
1
View file @
ee973b4c
__version__
=
'
2.8.4
_a3
'
__version__
=
'
2.8.4
'
This diff is collapsed.
Click to expand it.
satella/coding/transforms/__init__.py
+
8
−
8
View file @
ee973b4c
...
@@ -11,7 +11,10 @@ def stringify(obj: tp.Union[tp.Any], stringifier: tp.Callable[[tp.Any], str] = s
...
@@ -11,7 +11,10 @@ def stringify(obj: tp.Union[tp.Any], stringifier: tp.Callable[[tp.Any], str] = s
ie. if a dict, put every item and key (if a dict is given) through stringify.
ie. if a dict, put every item and key (if a dict is given) through stringify.
if a list, put every item through stringify
if a list, put every item through stringify
else just call stringify on it
else just call stringify on it.
Note that if you use recursively, then dicts and lists are allowed to be valid elements of the returned
representation!
:param obj: a list or a dict
:param obj: a list or a dict
:param stringifier: function that accepts any arguments and returns a string representation
:param stringifier: function that accepts any arguments and returns a string representation
...
@@ -19,13 +22,10 @@ def stringify(obj: tp.Union[tp.Any], stringifier: tp.Callable[[tp.Any], str] = s
...
@@ -19,13 +22,10 @@ def stringify(obj: tp.Union[tp.Any], stringifier: tp.Callable[[tp.Any], str] = s
:return: stringified object
:return: stringified object
"""
"""
if
isinstance
(
obj
,
collections
.
abc
.
Mapping
):
if
isinstance
(
obj
,
collections
.
abc
.
Mapping
):
if
recursively
:
make_str
=
(
lambda
obj2
:
stringify
(
obj2
,
stringifier
,
True
))
if
recursively
else
stringifier
stringifier
=
lambda
obj2
:
stringify
(
obj2
,
stringifier
=
stringifier
,
recursively
=
True
)
return
{
make_str
(
k
):
make_str
(
v
)
for
k
,
v
in
obj
.
items
()}
return
{
stringifier
(
k
):
stringifier
(
v
)
for
k
,
v
in
obj
.
items
()}
elif
isinstance
(
obj
,
collections
.
abc
.
Sequence
):
elif
isinstance
(
obj
,
collections
.
abc
.
Sequence
):
if
recursively
:
make_str
=
(
lambda
obj2
:
stringify
(
obj2
,
stringifier
,
True
))
if
recursively
else
stringifier
stringifier
=
lambda
obj2
:
stringify
(
obj2
,
stringifier
=
stringifier
,
recursively
=
True
)
return
[
make_str
(
v
)
for
v
in
obj
]
return
[
stringifier
(
v
)
for
v
in
obj
]
else
:
else
:
return
stringifier
(
obj
)
return
stringifier
(
obj
)
This diff is collapsed.
Click to expand it.
tests/test_coding/test_transforms.py
+
3
−
0
View file @
ee973b4c
...
@@ -13,3 +13,6 @@ class MyTestCase(unittest.TestCase):
...
@@ -13,3 +13,6 @@ class MyTestCase(unittest.TestCase):
lst2
=
[[
1
,
2
,
3
],
3
,
4
,
5
]
lst2
=
[[
1
,
2
,
3
],
3
,
4
,
5
]
self
.
assertEqual
(
stringify
(
lst2
),
[
'
[1, 2, 3]
'
,
'
3
'
,
'
4
'
,
'
5
'
])
self
.
assertEqual
(
stringify
(
lst2
),
[
'
[1, 2, 3]
'
,
'
3
'
,
'
4
'
,
'
5
'
])
self
.
assertEqual
(
stringify
(
lst2
,
recursively
=
True
),
[[
'
1
'
,
'
2
'
,
'
3
'
],
'
3
'
,
'
4
'
,
'
5
'
])
self
.
assertEqual
(
stringify
(
lst2
,
recursively
=
True
),
[[
'
1
'
,
'
2
'
,
'
3
'
],
'
3
'
,
'
4
'
,
'
5
'
])
dct2
=
{
1
:
[
1
,
2
,
3
]}
self
.
assertEqual
(
stringify
(
dct2
,
recursively
=
True
),
{
'
1
'
:
[
'
1
'
,
'
2
'
,
'
3
'
]})
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