Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support metaclass subclasses #48

Merged
merged 11 commits into from Apr 4, 2019

Conversation

2 participants
@mbustosorg
Copy link
Contributor

commented Apr 1, 2019

Descendants should check if the class is a Metaclass. Added test also.

@kernc
Copy link
Contributor

left a comment

Where is d.py (D) tested for?

Show resolved Hide resolved pdoc/__init__.py Outdated
@mbustosorg

This comment has been minimized.

Copy link
Contributor Author

commented Apr 1, 2019

@kernc

This comment has been minimized.

Copy link
Contributor

commented Apr 1, 2019

I think that's because self.obj.__subclasses__ is a bound method whereas type.__subclasses__ is unbound and can be passed the self.obj (meta)class parameter. Seems to work.

@mbustosorg

This comment has been minimized.

Copy link
Contributor Author

commented Apr 2, 2019

I tried that iteration and it failed when testing d.py. Did you see different results?

@kernc

This comment has been minimized.

Copy link
Contributor

commented Apr 2, 2019

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 ApiTest.test_subclasses() where you create a few local classes and call pdoc.Class(cls.__name__, sys, cls).subclasses() on them?

@mbustosorg

This comment has been minimized.

Copy link
Contributor Author

commented Apr 2, 2019

mbustosorg added some commits Apr 2, 2019

Show resolved Hide resolved pdoc/test/__init__.py Outdated
@mbustosorg

This comment has been minimized.

Copy link
Contributor Author

commented Apr 2, 2019

@kernc

This comment has been minimized.

Copy link
Contributor

commented Apr 2, 2019

No, no, I love how few extra lines are needed to define those classes! Just test pdoc API (pdoc.Class.subclasses) instead of Python API (type dunder methods). 😄

@kernc

This comment has been minimized.

Copy link
Contributor

commented Apr 2, 2019

Sorry, with any_module I meant it can be a dummy module just so long the constructor executes.

mbustosorg and others added some commits Apr 3, 2019

@kernc

This comment has been minimized.

Copy link
Contributor

commented Apr 4, 2019

Applied with slight modification. I see I have been oversimplifying my examples. Thanks for figuring it out! 😄

@kernc kernc changed the title Bugfix metaclass Support metaclass subclasses Apr 4, 2019

@kernc kernc merged commit ec59549 into pdoc3:master Apr 4, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.