Skip to content

Commit 63f7115

Browse files
Евгений БлиновЕвгений Блинов
authored andcommitted
Add Table of Contents and split Usage into dedicated sections
1 parent f488827 commit 63f7115

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
This library is needed to obtain the source code of functions at runtime. It can be used, for example, as a basis for libraries that work with [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree) on the fly. In fact, it is a thin layer built around [`inspect.getsource`](https://docs.python.org/3/library/inspect.html#inspect.getsource) and [`dill.source.getsource`](https://dill.readthedocs.io/en/latest/dill.html#dill.source.getsource).
2222

2323

24+
## Table of contents
25+
26+
- [**Installation**](#installation)
27+
- [**Get dirty sources**](#get-dirty-sources)
28+
- [**Get clear sources**](#get-clear-sources)
29+
- [**Get hashes**](#get-hashes)
30+
2431
## Installation
2532

2633
You can install [`getsources`](https://pypi.python.org/pypi/getsources) using pip:
@@ -29,10 +36,10 @@ You can install [`getsources`](https://pypi.python.org/pypi/getsources) using pi
2936
pip install getsources
3037
```
3138

32-
You can also quickly try out this and other packages without having to install using [instld](https://github.com/pomponchik/instld).
39+
You can also quickly try this package and others without installing them via [instld](https://github.com/pomponchik/instld).
3340

3441

35-
## Usage
42+
## Get dirty sources
3643

3744
The basic function of the library is `getsource`, which works similarly to the function of the same name from the standard library:
3845

@@ -50,7 +57,10 @@ print(getsource(function))
5057
Unlike its counterpart from the standard library, this thing can also work:
5158

5259
- With lambda functions (however, keep in mind that the entire text of the line where they are defined is returned, and if there are multiple lambda functions there, the library won't let you distinguish between them)
53-
- With functions defined inside REPL
60+
- With functions defined inside `REPL`
61+
62+
63+
## Get clear sources
5464

5565
We also often need to trim excess indentation from a function object to make it easier to further process the resulting code. To do this, use the `getclearsource` function:
5666

@@ -68,7 +78,10 @@ print(getclearsource(SomeClass.method))
6878
#> ...
6979
```
7080

71-
As you can see, the resulting source code text has no extra indentation, but in all other respects this function is completely identical to the usual `getsource`.
81+
As you can see, the resulting source code text has no extra indentation, but in all other respects this function is completely identical to the [usual `getsource`](#get-dirty-sources).
82+
83+
84+
## Get hashes
7285

7386
In some cases, you may not care what exactly is inside a function, but you need to distinguish between functions with different contents. In this case, the `getsourcehash` function is useful, as it returns a short string representation of the function’s source code hash:
7487

0 commit comments

Comments
 (0)