Further example tinkering

This commit is contained in:
Dave Halter
2020-03-14 15:47:32 +01:00
parent fbba7714e4
commit e811651b00

View File

@@ -72,15 +72,16 @@ Errors
Examples Examples
-------- --------
Completions: Completions
~~~~~~~~~~~
.. sourcecode:: python .. sourcecode:: python
>>> import jedi >>> import jedi
>>> source = '''import json; json.l''' >>> code = '''import json; json.l'''
>>> script = jedi.Script(source, path='') >>> script = jedi.Script(code, path='example.py')
>>> script >>> script
<jedi.api.Script object at 0x2121b10> <Script: 'example.py' <SameEnvironment: 3.5.2 in /usr>>
>>> completions = script.complete(1, 19) >>> completions = script.complete(1, 19)
>>> completions >>> completions
[<Completion: load>, <Completion: loads>] [<Completion: load>, <Completion: loads>]
@@ -91,12 +92,13 @@ Completions:
>>> completions[1].name >>> completions[1].name
'loads' 'loads'
Definitions / Goto: Type Inference / Goto
~~~~~~~~~~~~~~~~~~~~~
.. sourcecode:: python .. sourcecode:: python
>>> import jedi >>> import jedi
>>> source = '''def my_func(): >>> code = '''def my_func():
... print 'called' ... print 'called'
... ...
... alias = my_func ... alias = my_func
@@ -104,25 +106,26 @@ Definitions / Goto:
... inception = my_list[2] ... inception = my_list[2]
... ...
... inception()''' ... inception()'''
>>> script = jedi.Script(source, path='') >>> script = jedi.Script(code)
>>> >>>
>>> script.goto(8, 1) >>> script.goto(8, 1)
[<Definition inception=my_list[2]>] [<Definition full_name='__main__.inception', description='inception = my_list[2]'>]
>>> >>>
>>> script.infer(8, 1) >>> script.infer(8, 1)
[<Definition def my_func>] [<Definition full_name='__main__.my_func', description='def my_func'>]
References: References
~~~~~~~~~~
.. sourcecode:: python .. sourcecode:: python
>>> import jedi >>> import jedi
>>> source = '''x = 3 >>> code = '''x = 3
... if 1 == 2: ... if 1 == 2:
... x = 4 ... x = 4
... else: ... else:
... del x''' ... del x'''
>>> script = jedi.Script(source, '') >>> script = jedi.Script(code)
>>> rns = script.get_references(5, 8) >>> rns = script.get_references(5, 8)
>>> rns >>> rns
[<Definition full_name='__main__.x', description='x = 3'>, [<Definition full_name='__main__.x', description='x = 3'>,