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
38e4e525
Commit
38e4e525
authored
5 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into develop
parents
0bae016c
a2d62d3f
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
satella/coding/metaclasses.py
+16
-18
16 additions, 18 deletions
satella/coding/metaclasses.py
tests/test_coding/test_metaclasses.py
+2
-0
2 additions, 0 deletions
tests/test_coding/test_metaclasses.py
with
18 additions
and
18 deletions
satella/coding/metaclasses.py
+
16
−
18
View file @
38e4e525
...
...
@@ -15,7 +15,7 @@ __all__ = ['metaclass_maker', 'wrap_with', 'dont_wrap', 'wrap_property',
'
DocsFromParent
'
]
class
DocsFromParent
(
type
):
def
DocsFromParent
(
name
,
bases
,
dictionary
):
"""
A metaclass that fetches missing docstring
'
s for methods from the classes
'
bases,
looked up BFS.
...
...
@@ -29,23 +29,21 @@ class DocsFromParent(type):
>>>
...
>>>
assert
Child
.
test
.
__doc__
==
'
my docstring
'
"""
def
__call__
(
cls
,
name
,
bases
,
dictionary
):
def
extract_bases
(
obj
):
if
isinstance
(
obj
,
tuple
):
return
obj
else
:
return
[
v_base
for
v_base
in
obj
.
__bases__
if
v_base
is
not
object
]
for
key
,
value
in
dictionary
.
items
():
if
callable
(
value
)
and
not
value
.
__doc__
:
for
base
in
walk
(
bases
,
extract_bases
,
deep_first
=
False
):
if
hasattr
(
base
,
key
):
if
getattr
(
base
,
key
).
__doc__
:
value
.
__doc__
=
getattr
(
base
,
key
).
__doc__
dictionary
[
key
]
=
value
break
return
super
().
__call__
(
name
,
bases
,
dictionary
)
def
extract_bases
(
cls
):
if
isinstance
(
cls
,
(
tuple
,
list
)):
return
cls
else
:
return
[
v_base
for
v_base
in
cls
.
__bases__
if
v_base
is
not
object
]
for
key
,
value
in
dictionary
.
items
():
if
not
value
.
__doc__
and
callable
(
value
):
for
base
in
walk
(
bases
,
extract_bases
,
deep_first
=
False
):
if
hasattr
(
base
,
key
):
if
getattr
(
base
,
key
).
__doc__
:
value
.
__doc__
=
getattr
(
base
,
key
).
__doc__
dictionary
[
key
]
=
value
break
return
type
(
name
,
bases
,
dictionary
)
def
skip_redundant
(
iterable
,
skip_set
=
None
):
...
...
This diff is collapsed.
Click to expand it.
tests/test_coding/test_metaclasses.py
+
2
−
0
View file @
38e4e525
...
...
@@ -33,6 +33,8 @@ class TestMetaclasses(unittest.TestCase):
"""
my docstring
"""
class
Child
(
Father
,
metaclass
=
DocsFromParent
):
a
:
int
=
2
def
test
(
self
):
pass
...
...
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