-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
bpo-6691: Support for nested classes and functions in pyclbr #2503
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
Changes from 5 commits
b94e281
a726dc1
7105eed
bcc1760
83b10c7
b9243d7
2c28520
082e469
ed1b892
259616c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,13 +11,12 @@ | |
-------------- | ||
|
||
The :mod:`pyclbr` module can be used to determine some limited information | ||
about the classes, methods and top-level functions defined in a module. The | ||
information provided is sufficient to implement a traditional three-pane | ||
class browser. The information is extracted from the source code rather | ||
than by importing the module, so this module is safe to use with untrusted | ||
code. This restriction makes it impossible to use this module with modules | ||
not implemented in Python, including all standard and optional extension | ||
modules. | ||
about the classes, methods, and functions defined in a module. The | ||
information provided is sufficient to implement a module browser. The | ||
information is extracted from the source code rather than by importing the | ||
module, so this module is safe to use with untrusted code. This restriction | ||
makes it impossible to use this module with modules not implemented in Python, | ||
including all standard and optional extension modules. | ||
|
||
|
||
.. function:: readmodule(module, path=None) | ||
|
@@ -32,85 +31,102 @@ modules. | |
.. function:: readmodule_ex(module, path=None) | ||
|
||
Like :func:`readmodule`, but the returned dictionary, in addition to | ||
mapping class names to class descriptor objects, also maps top-level | ||
function names to function descriptor objects. Moreover, if the module | ||
mapping class names to class descriptor objects, also maps function | ||
names to function descriptor objects. Moreover, if the module | ||
being read is a package, the key ``'__path__'`` in the returned | ||
dictionary has as its value a list which contains the package search | ||
path. | ||
|
||
|
||
.. _pyclbr-class-objects: | ||
.. _pyclbr-object-objects: | ||
|
||
Class Objects | ||
------------- | ||
Object Objects | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to make Object private and delete this part of the doc. |
||
-------------- | ||
The class :class:`Object` is the base class for the classes | ||
:class:`Class` and :class:`Function`. It provides the following | ||
data members: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An added in 3.7 note is needed. I am not sure if it goes here or after attributes. In any case, most attributes were already common to Class and Function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addition notes looks good to me, but I am not clear on the rules. See comment below about core-mentorship question. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Approval did not collapse these. |
||
|
||
The :class:`Class` objects used as values in the dictionary returned by | ||
:func:`readmodule` and :func:`readmodule_ex` provide the following data | ||
attributes: | ||
|
||
.. attribute:: Object.module | ||
|
||
.. attribute:: Class.module | ||
The name of the module defining the object described. | ||
|
||
The name of the module defining the class described by the class descriptor. | ||
|
||
.. attribute:: Object.name | ||
|
||
.. attribute:: Class.name | ||
The name of the object. | ||
|
||
The name of the class. | ||
|
||
.. attribute:: Object.file | ||
|
||
.. attribute:: Class.super | ||
Name of the file in which the object was defined. | ||
|
||
A list of :class:`Class` objects which describe the immediate base | ||
classes of the class being described. Classes which are named as | ||
superclasses but which are not discoverable by :func:`readmodule` are | ||
listed as a string with the class name instead of as :class:`Class` | ||
objects. | ||
|
||
.. attribute:: Object.lineno | ||
|
||
.. attribute:: Class.methods | ||
The line number in the file named by :attr:`~Object.file` where | ||
the definition of the object started. | ||
|
||
A dictionary mapping method names to line numbers. | ||
|
||
.. attribute:: Object.parent | ||
|
||
.. attribute:: Class.file | ||
The parent of this object, if any. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New attribute added in 3.7 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment misplaced. Actual new attribute now tagged. |
||
|
||
Name of the file containing the ``class`` statement defining the class. | ||
.. versionadded:: 3.7 | ||
|
||
|
||
.. attribute:: Class.lineno | ||
.. attribute:: Object.children | ||
|
||
The line number of the ``class`` statement within the file named by | ||
:attr:`~Class.file`. | ||
A dictionary mapping object names to the objects that are defined inside the | ||
namespace created by the current object. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New attribute added in 3.7. By inheritance, added in 3.7 to Class and Function. As I say below, this new attribute should be 'children'. |
||
|
||
.. versionadded:: 3.7 | ||
|
||
.. _pyclbr-function-objects: | ||
|
||
Function Objects | ||
---------------- | ||
.. versionchanged:: 3.7 | ||
:class:`Object` was added as a base class for :class:`Class` and | ||
:class:`Function` and, except as otherwise noted, the attributes | ||
were previously common to those two classes. | ||
|
||
The :class:`Function` objects used as values in the dictionary returned by | ||
:func:`readmodule_ex` provide the following attributes: | ||
|
||
|
||
.. attribute:: Function.module | ||
.. _pyclbr-class-objects: | ||
|
||
The name of the module defining the function described by the function | ||
descriptor. | ||
Class Objects | ||
------------- | ||
|
||
:class:`Class` is a subclass of :class:`Object` whose objects are used as values | ||
in the dictionary returned by :func:`readmodule` and :func:`readmodule_ex`. | ||
In addition to the attributes from :class:`Object`, :class:`Class` objects | ||
also provide the following attributes: | ||
|
||
|
||
.. attribute:: Class.super | ||
|
||
A list of :class:`Class` objects which describe the immediate base | ||
classes of the class being described. Classes which are named as | ||
superclasses but which are not discoverable by :func:`readmodule` are | ||
listed as a string with the class name instead of as :class:`Class` | ||
objects. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and 'methods' below, with the 'old' attributes in Object, constitute the old set of attributes for Class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No specific fix needed. |
||
|
||
|
||
.. attribute:: Function.name | ||
.. attribute:: Class.methods | ||
|
||
The name of the function. | ||
A dictionary mapping method names to line numbers. | ||
|
||
|
||
.. attribute:: Function.file | ||
.. versionchanged:: 3.7 | ||
:class:`Class` became a subclass of :class:`Object`. | ||
|
||
Name of the file containing the ``def`` statement defining the function. | ||
|
||
.. _pyclbr-function-objects: | ||
|
||
.. attribute:: Function.lineno | ||
Function Objects | ||
---------------- | ||
|
||
The line number of the ``def`` statement within the file named by | ||
:attr:`~Function.file`. | ||
:class:`Function` is a subclass of :class:`Object` whose objects are used as | ||
values in the dictionary returned by :func:`readmodule_ex`. The only instance | ||
attributes are those from :class:`Object`. | ||
|
||
.. versionchanged:: 3.7 | ||
:class:`Function` became a subclass of :class:`Object`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume that the opening paragraph should be revised. 'top-level' removed. I don't know what a 'traditional three-pane class browser' is, The addition of functions makes this a module browser.
readmodule_ex: since there is not another function added, I presume that the return of readmodule_ex has been expanded so that 'top-level' is obsolete here too. I will look at the actual behavior before editing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, a72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am guessing that I cannot hide this as outdated because there was no subsequent change at this location. I will try approving and then making a new review.