Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport metaclass subclasses #48
Conversation
mbustosorg
added some commits
Mar 29, 2019
kernc
reviewed
Apr 1, 2019
|
Where is d.py ( |
pdoc/__init__.py Outdated
This comment has been minimized.
This comment has been minimized.
|
d.py is tested as part of the example_pkg test.
Calling with self.obj doesn't work because non metaclass type classes take
no arguments. The tests fail that way.
Thanks,
mauricio
…On Mon, Apr 1, 2019 at 5:36 AM kernc ***@***.***> wrote:
***@***.**** commented on this pull request.
Where is *d.py* (D) tested for?
------------------------------
In pdoc/__init__.py
<#48 (comment)>:
> @@ -1210,6 +1210,10 @@ def subclasses(self) -> List['Class']:
The objects in the list are of type `pdoc.Class` if available,
and `pdoc.External` otherwise.
"""
+ if issubclass(self.obj, type):
+ return [self.module.find_class(c)
+ for c in self.obj.__subclasses__(self.obj)]
+
I think the whole method can be replaced with:
return [self.module.find_class(c)
for c in type.__subclasses__(self.obj)]
This makes the branch redundant as it works for both cases.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#48 (review)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAt-cWy7IPNj1NUngbyZGDvkG9zAElU4ks5vcf03gaJpZM4cUuQK>
.
|
This comment has been minimized.
This comment has been minimized.
|
I think that's because |
This comment has been minimized.
This comment has been minimized.
|
I tried that iteration and it failed when testing d.py. Did you see different results? |
This comment has been minimized.
This comment has been minimized.
|
Seems to work here on Python 3.5: >>> class A: pass
>>> class B(type): pass
>>> class C(A): pass
>>> class D(B): pass
>>> type.__subclasses__(A)
[<class '__main__.C'>]
>>> type.__subclasses__(B)
[<class '__main__.D'>]In addition, would you consider creating a new test |
This comment has been minimized.
This comment has been minimized.
|
Yes. I'll have a look at why I'm seeing different results as you and will
create the new test case.
…On Mon, Apr 1, 2019 at 6:30 PM kernc ***@***.***> wrote:
Seems to work here:
>>> class A: pass>>> class B(type): pass>>> class C(A): pass>>> class D(B): pass>>> type.__subclasses__(A)
[<class '__main__.C'>]>>> type.__subclasses__(B)
[<class '__main__.D'>]
In addition, would you consider creating a new test
ApiTest.test_subclasses() where you create a few local classes and call pdoc.Class(cls.__name__,
sys, cls).subclasses() on them?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#48 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAt-cU1BRvSFb8Hj2VWliuuXVjXAZFLeks5vcrKzgaJpZM4cUuQK>
.
|
mbustosorg
added some commits
Apr 2, 2019
kernc
reviewed
Apr 2, 2019
pdoc/test/__init__.py Outdated
kernc
reviewed
Apr 2, 2019
This comment has been minimized.
This comment has been minimized.
|
So you would recommend creating a new submodule that includes these classes
instead of in the code like this?
…On Tue, Apr 2, 2019 at 3:18 PM kernc ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In pdoc/test/example_pkg/_test_linking/d.py
<#48 (comment)>:
> @@ -0,0 +1,10 @@
+class D(type):
+
+ def __init__(cls, name, bases, dct):
+ super().__init__(cls, name, bases, dct)
+ cls._instance = None
+
+ def __call__(cls, *args, **kwargs):
+ if cls._instance is None:
+ cls._instance.__call__(*args, **kwargs)
+ return cls._instance
Afterwards, this file is obsolete.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#48 (review)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAt-cdUVF7uFS_0tZTWiOOVnzxtPhBp9ks5vc9cagaJpZM4cUuQK>
.
|
This comment has been minimized.
This comment has been minimized.
|
No, no, I love how few extra lines are needed to define those classes! Just test pdoc API ( |
This comment has been minimized.
This comment has been minimized.
|
Sorry, with |
mbustosorg
and others
added some commits
Apr 3, 2019
This comment has been minimized.
This comment has been minimized.
|
Applied with slight modification. I see I have been oversimplifying my examples. Thanks for figuring it out! |
mbustosorg commentedApr 1, 2019
Descendants should check if the class is a Metaclass. Added test also.