Last active
October 1, 2024 23:41
-
-
Save jakelevi1996/0aa7bf336354c70d093d987f28fa5051 to your computer and use it in GitHub Desktop.
Examples of the ways in which `inspect` can be used to inspect functions, classes, and methods defined within a module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import inspect | |
from jutility import plotting, util | |
x = [ | |
(name, value) | |
for name, value in inspect.getmembers(plotting) | |
if inspect.isfunction(value) | |
and name[0] != "_" | |
] | |
print(*x, sep="\n") | |
util.Printer().hline() | |
x = [ | |
(name, value) | |
for name, value in inspect.getmembers(plotting) | |
if inspect.isclass(value) | |
and name[0] != "_" | |
] | |
print(*x, sep="\n") | |
util.Printer().hline() | |
name, value = x[0] | |
print(name, value) | |
x = [ | |
(name, value) | |
for name, value in inspect.getmembers(value) | |
if inspect.isfunction(value) | |
] | |
print(*x, sep="\n") | |
util.Printer().hline() | |
for name, value in x: | |
print(value, repr(inspect.signature(value))) | |
# ('confidence_bounds', <function confidence_bounds at 0x7a338cb29510>) | |
# ('plot', <function plot at 0x7a336f512950>) | |
# ('set_latex_params', <function set_latex_params at 0x7a336f513c70>) | |
# ---------------------------------------------------------------------------------------------------- | |
# ('AxLine', <class 'jutility.plotting.AxLine'>) | |
# ('AxisProperties', <class 'jutility.plotting.AxisProperties'>) | |
# ('Bar', <class 'jutility.plotting.Bar'>) | |
# ('Circle', <class 'jutility.plotting.Circle'>) | |
# ('ColourBar', <class 'jutility.plotting.ColourBar'>) | |
# ('ColourMesh', <class 'jutility.plotting.ColourMesh'>) | |
# ('ColourPicker', <class 'jutility.plotting.ColourPicker'>) | |
# ('Contour', <class 'jutility.plotting.Contour'>) | |
# ('ContourFilled', <class 'jutility.plotting.ContourFilled'>) | |
# ('Empty', <class 'jutility.plotting.Empty'>) | |
# ('FigureLegend', <class 'jutility.plotting.FigureLegend'>) | |
# ('FigureProperties', <class 'jutility.plotting.FigureProperties'>) | |
# ('FillBetween', <class 'jutility.plotting.FillBetween'>) | |
# ('Gif', <class 'jutility.plotting.Gif'>) | |
# ('HLine', <class 'jutility.plotting.HLine'>) | |
# ('HSpan', <class 'jutility.plotting.HSpan'>) | |
# ('Hist', <class 'jutility.plotting.Hist'>) | |
# ('ImShow', <class 'jutility.plotting.ImShow'>) | |
# ('Legend', <class 'jutility.plotting.Legend'>) | |
# ('LegendSubplot', <class 'jutility.plotting.LegendSubplot'>) | |
# ('Line', <class 'jutility.plotting.Line'>) | |
# ('MultiPlot', <class 'jutility.plotting.MultiPlot'>) | |
# ('NoisyData', <class 'jutility.plotting.NoisyData'>) | |
# ('Plottable', <class 'jutility.plotting.Plottable'>) | |
# ('Polygon', <class 'jutility.plotting.Polygon'>) | |
# ('Quiver', <class 'jutility.plotting.Quiver'>) | |
# ('Scatter', <class 'jutility.plotting.Scatter'>) | |
# ('Step', <class 'jutility.plotting.Step'>) | |
# ('Subplot', <class 'jutility.plotting.Subplot'>) | |
# ('Text', <class 'jutility.plotting.Text'>) | |
# ('VLine', <class 'jutility.plotting.VLine'>) | |
# ('VSpan', <class 'jutility.plotting.VSpan'>) | |
# ---------------------------------------------------------------------------------------------------- | |
# AxLine <class 'jutility.plotting.AxLine'> | |
# ('__init__', <function Plottable.__init__ at 0x7a336f511480>) | |
# ('__repr__', <function Plottable.__repr__ at 0x7a336f511900>) | |
# ('_expand_abbreviated_keys', <function Plottable._expand_abbreviated_keys at 0x7a336f5117e0>) | |
# ('_get_abbreviated_keys_dict', <function Plottable._get_abbreviated_keys_dict at 0x7a336f511750>) | |
# ('_get_default_kwargs', <function Line._get_default_kwargs at 0x7a336f511ab0>) | |
# ('get_handle', <function Line.get_handle at 0x7a336f511a20>) | |
# ('has_label', <function Plottable.has_label at 0x7a336f511870>) | |
# ('plot', <function AxLine.plot at 0x7a336f511c60>) | |
# ('set_options', <function Plottable.set_options at 0x7a336f511630>) | |
# ---------------------------------------------------------------------------------------------------- | |
# <function Plottable.__init__ at 0x7a336f511480> <Signature (self, *args, **kwargs)> | |
# <function Plottable.__repr__ at 0x7a336f511900> <Signature (self)> | |
# <function Plottable._expand_abbreviated_keys at 0x7a336f5117e0> <Signature (self)> | |
# <function Plottable._get_abbreviated_keys_dict at 0x7a336f511750> <Signature (self)> | |
# <function Line._get_default_kwargs at 0x7a336f511ab0> <Signature (self)> | |
# <function Line.get_handle at 0x7a336f511a20> <Signature (self)> | |
# <function Plottable.has_label at 0x7a336f511870> <Signature (self)> | |
# <function AxLine.plot at 0x7a336f511c60> <Signature (self, axis: matplotlib.axes._axes.Axes)> | |
# <function Plottable.set_options at 0x7a336f511630> <Signature (self, **kwargs)> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment