Skip to content

Commit

Permalink
Try each of the 'is' functions from inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam Cooke committed May 18, 2017
1 parent 5a97550 commit 90f0aa1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ All notable changes to this project will be documented in this file. This
project adheres to `Semantic Versioning <http://semver.org>`__ as of v1.1.0.


.. Unreleased_
.. --------------------
Unreleased_
--------------------

**Added**

- Test each of the ``is`` functions from the *inspect* module, such as
``isclass`` and ``isgenerator``, and include them in the result.


v1.3.2_ / 2016-04-30
Expand Down
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ Call ``see(an_object)`` to see what you can do with ``an_object``. ::
.denominator .from_bytes() .imag .numerator
.real .to_bytes()

>>> async def hello_world():
... print("Hello World!")
...
>>> see(hello_world)
iscoroutinefunction isfunction isroutine ()
< <= == != >
>= dir() hash() repr() str()


Startup
-------
Expand Down
10 changes: 10 additions & 0 deletions see/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def __repr__(self):
subsequent_indent=indent)


# Get all the 'is' functions from the inspect module.
INSPECT_FUNCS = tuple((name, getattr(inspect, name))
for name in dir(inspect) if name.startswith('is'))


def see(obj=DEFAULT_ARG, pattern=None, r=None):
"""
Inspect an object. Like the ``dir()`` builtin, but easier on the eyes.
Expand Down Expand Up @@ -94,6 +99,11 @@ def see(obj=DEFAULT_ARG, pattern=None, r=None):
attrs = dir(obj)

if not use_locals:

for name, func in INSPECT_FUNCS:
if func(obj):
actions.append(name)

for feature in FEATURES:
if feature.match(obj, attrs):
actions.append(feature.symbol)
Expand Down

0 comments on commit 90f0aa1

Please sign in to comment.