Skip to content

Commit 1572f2f

Browse files
Adds enclosing ranges to function and class definitions (#132)
Co-authored-by: Varun Gandhi <varun.gandhi@sourcegraph.com>
1 parent f5e9aee commit 1572f2f

File tree

53 files changed

+568
-611
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+568
-611
lines changed

packages/pyright-scip/snapshots/input/builtin_imports/builtin_imports.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# format-options: showDocs
2+
13
import re
24
from typing import Callable, Optional
35

packages/pyright-scip/snapshots/input/class_nohint/class_nohint.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# format-options: showDocs
2+
13
class Example:
24
# Note, only y has a type hint
35
y: int
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# format-options: showRanges
2+
def class_decorator(cls):
3+
def wrapper(*args, **kwargs):
4+
return cls(*args, **kwargs)
5+
return wrapper
6+
7+
@class_decorator
8+
class Test:
9+
def __init__(self, x: float):
10+
self.x = x
11+
12+
def test(self) -> float:
13+
return self.x
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# format-options: showRanges
2+
class Test():
3+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# format-options: showRanges
2+
def decorator(func):
3+
def wrapper(*args, **kwargs):
4+
return func(*args, **kwargs)
5+
return wrapper
6+
7+
@decorator
8+
def func(x: float) -> float:
9+
test = x
10+
11+
return test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# format-options: showRanges
2+
def simple(x):
3+
return x

packages/pyright-scip/snapshots/input/unique/field_docstring.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# format-options: showDocs
2+
13
class ClassWithField:
24

35
a: int
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# format-options: showDocs
2+
13
class ClassWithInferredField:
24
def __init__(self, b: int):
35
self.b = b

packages/pyright-scip/snapshots/input/unique/module_docstring.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# format-options: showDocs
2+
13
"""
24
This is a docstring for this module
35
"""
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
# < definition scip-python python snapshot-util 0.1 actual/__init__:
2-
#documentation (module) actual
32

43
import aliased
54
# ^^^^^^^ reference snapshot-util 0.1 aliased/__init__:
65
import aliased as A
76
# ^^^^^^^ reference snapshot-util 0.1 aliased/__init__:
87
# ^ reference local 0
9-
# documentation ```python
10-
# > (module) A
11-
# > ```
128

139
print(A.SOME_CONSTANT)
1410
#^^^^ reference python-stdlib 3.11 builtins/print().
15-
#external documentation ```python
16-
# > (function) def print(
17-
# > *values: object,
18-
# > sep: str | None = " ",
19-
# > end: str | None = "\n",
20-
# > file: SupportsWrite[str] | None = No...
21-
# > flush: Literal[False] = False
22-
# > ) -> None
23-
# > ```
2411
# ^ reference local 0
2512
# ^^^^^^^^^^^^^ reference snapshot-util 0.1 aliased/SOME_CONSTANT.
2613

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# < definition scip-python python snapshot-util 0.1 aliased/__init__:
2-
#documentation (module) aliased
32

43
SOME_CONSTANT = "Some Constant"
54
#^^^^^^^^^^^^ definition snapshot-util 0.1 aliased/SOME_CONSTANT.
6-
#documentation ```python
7-
# > builtins.str
8-
# > ```
95

packages/pyright-scip/snapshots/output/builtin_imports/builtin_imports.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# < definition scip-python python snapshot-util 0.1 builtin_imports/__init__:
22
#documentation (module) builtin_imports
33

4+
# format-options: showDocs
5+
46
import re
57
# ^^ reference python-stdlib 3.11 re/__init__:
68
from typing import Callable, Optional

packages/pyright-scip/snapshots/output/class_nohint/class_nohint.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# < definition scip-python python snapshot-util 0.1 class_nohint/__init__:
22
#documentation (module) class_nohint
33

4+
# format-options: showDocs
5+
46
class Example:
57
# ^^^^^^^ definition snapshot-util 0.1 class_nohint/Example#
68
# documentation ```python

packages/pyright-scip/snapshots/output/comprehensions/comp.py

-48
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,42 @@
11
# < definition scip-python python snapshot-util 0.1 comp/__init__:
2-
#documentation (module) comp
32

43
def something(x):
54
# ^^^^^^^^^ definition snapshot-util 0.1 comp/something().
6-
# documentation ```python
7-
# > def something(
8-
# > x
9-
# > ):
10-
# > ```
115
# ^ definition snapshot-util 0.1 comp/something().(x)
126
return 2 * x
137
# ^ reference snapshot-util 0.1 comp/something().(x)
148

159
_ = [x for x in "should be local 0"]
1610
# ^ reference local 0
1711
# ^ definition local 0
18-
# documentation ```python
19-
# > (variable) x: str
20-
# > ```
2112
_ = [something(x) for x in "should be local 1"]
2213
# ^^^^^^^^^ reference snapshot-util 0.1 comp/something().
2314
# ^ reference local 1
2415
# ^ definition local 1
25-
# documentation ```python
26-
# > (variable) x: str
27-
# > ```
2816
_ = [something(x) for x in "should be local 2" if x == "s"]
2917
# ^^^^^^^^^ reference snapshot-util 0.1 comp/something().
3018
# ^ reference local 2
3119
# ^ definition local 2
32-
# documentation ```python
33-
# > (variable) x: str
34-
# > ```
3520
# ^ reference local 2
3621
_ = {k: x for (k, x) in enumerate(range(10))}
3722
# ^ reference local 3
3823
# ^ reference local 4
3924
# ^ definition local 3
40-
# documentation ```python
41-
# > (variable) k: int
42-
# > ```
4325
# ^ definition local 4
44-
# documentation ```python
45-
# > (variable) x: int
46-
# > ```
4726
# ^^^^^^^^^ reference python-stdlib 3.11 builtins/enumerate#
48-
# external documentation ```python
49-
# > class enumerate(
50-
# > iterable: Iterable[int],
51-
# > start: int = ...
52-
# > )
53-
# > ```
5427
# ^^^^^ reference python-stdlib 3.11 builtins/range#
55-
# external documentation ```python
56-
# > class range(
57-
# > __stop: SupportsIndex,
58-
# > /
59-
# > )
60-
# > ```
6128

6229

6330
asdf = (var for var in [1, 2, 3] if var % 2 == 0)
6431
#^^^ definition snapshot-util 0.1 comp/asdf.
65-
#documentation ```python
66-
# > typing.Generator
67-
# > ```
6832
# ^^^ reference local 5
6933
# ^^^ definition local 5
70-
# documentation ```python
71-
# > (variable) var: int
72-
# > ```
7334
# ^^^ reference local 5
7435
for var in asdf:
7536
# ^^^ definition snapshot-util 0.1 comp/var.
7637
# ^^^^ reference snapshot-util 0.1 comp/asdf.
7738
print(var)
7839
# ^^^^^ reference python-stdlib 3.11 builtins/print().
79-
# external documentation ```python
80-
# > (function) def print(
81-
# > *values: object,
82-
# > sep: str | None = " ",
83-
# > end: str | None = "\n",
84-
# > file: SupportsWrite[str] | None = No...
85-
# > flush: Literal[False] = False
86-
# > ) -> None
87-
# > ```
8840
# ^^^ reference snapshot-util 0.1 comp/var.
8941

9042
# TODO: ListComprehensions with if
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
# < definition scip-python python snapshot-util 0.1 __main__/__init__:
2-
#documentation (module) __main__
32

43

54
if __name__ == '__main__':
65
# ^^^^^^^^ reference python-stdlib 3.11 builtins/__name__#
7-
# external documentation ```python
8-
# > __name__: str
9-
# > ```
106
print("main")
117
# ^^^^^ reference python-stdlib 3.11 builtins/print().
12-
# external documentation ```python
13-
# > (function) def print(
14-
# > *values: object,
15-
# > sep: str | None = " ",
16-
# > end: str | None = "\n",
17-
# > file: SupportsWrite[str] | None = No...
18-
# > flush: Literal[False] = False
19-
# > ) -> None
20-
# > ```
218

229

packages/pyright-scip/snapshots/output/empty_project_name_version/main.py

-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
# < definition scip-python python . . main/__init__:
2-
#documentation (module) main
32

43
def main():
54
# ^^^^ definition . . main/main().
6-
# documentation ```python
7-
# > def main(): # -> None:
8-
# > ```
95
pass
106

117
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# < definition scip-python python snapshot-util 0.1 advanced/__init__:
2+
3+
# format-options: showRanges
4+
# < start enclosing_range scip-python python snapshot-util 0.1 advanced/class_decorator().
5+
def class_decorator(cls):
6+
# ^^^^^^^^^^^^^^^ definition snapshot-util 0.1 advanced/class_decorator().
7+
# ^^^ definition snapshot-util 0.1 advanced/class_decorator().(cls)
8+
# ⌄ start enclosing_range scip-python python snapshot-util 0.1 advanced/class_decorator().wrapper().
9+
def wrapper(*args, **kwargs):
10+
# ^^^^^^^ definition snapshot-util 0.1 advanced/class_decorator().wrapper().
11+
# ^^^^ definition snapshot-util 0.1 advanced/class_decorator().wrapper().(args)
12+
# ^^^^^^ definition snapshot-util 0.1 advanced/class_decorator().wrapper().(kwargs)
13+
return cls(*args, **kwargs)
14+
# ^^^ reference snapshot-util 0.1 advanced/class_decorator().(cls)
15+
# ^^^^ reference snapshot-util 0.1 advanced/class_decorator().wrapper().(args)
16+
# ^^^^^^ reference snapshot-util 0.1 advanced/class_decorator().wrapper().(kwargs)
17+
# ^ end enclosing_range scip-python python snapshot-util 0.1 advanced/class_decorator().wrapper().
18+
return wrapper
19+
# ^^^^^^^ reference snapshot-util 0.1 advanced/class_decorator().wrapper().
20+
# < end enclosing_range scip-python python snapshot-util 0.1 advanced/class_decorator().
21+
22+
# < start enclosing_range scip-python python snapshot-util 0.1 advanced/Test#
23+
@class_decorator
24+
#^^^^^^^^^^^^^^^ reference snapshot-util 0.1 advanced/class_decorator().
25+
class Test:
26+
# ^^^^ definition snapshot-util 0.1 advanced/Test#
27+
# ⌄ start enclosing_range scip-python python snapshot-util 0.1 advanced/Test#__init__().
28+
def __init__(self, x: float):
29+
# ^^^^^^^^ definition snapshot-util 0.1 advanced/Test#__init__().
30+
# ^^^^ definition snapshot-util 0.1 advanced/Test#__init__().(self)
31+
# ^ definition snapshot-util 0.1 advanced/Test#__init__().(x)
32+
# ^^^^^ reference python-stdlib 3.11 builtins/float#
33+
self.x = x
34+
# ^^^^ reference snapshot-util 0.1 advanced/Test#__init__().(self)
35+
# ^ definition snapshot-util 0.1 advanced/Test#x.
36+
# ^ reference snapshot-util 0.1 advanced/Test#__init__().(x)
37+
# ^ end enclosing_range scip-python python snapshot-util 0.1 advanced/Test#__init__().
38+
39+
# ⌄ start enclosing_range scip-python python snapshot-util 0.1 advanced/Test#test().
40+
def test(self) -> float:
41+
# ^^^^ definition snapshot-util 0.1 advanced/Test#test().
42+
# ^^^^ definition snapshot-util 0.1 advanced/Test#test().(self)
43+
# ^^^^^ reference python-stdlib 3.11 builtins/float#
44+
return self.x
45+
# ^^^^ reference snapshot-util 0.1 advanced/Test#test().(self)
46+
# ^ reference snapshot-util 0.1 advanced/Test#x.
47+
# ^ end enclosing_range scip-python python snapshot-util 0.1 advanced/Test#test().
48+
# < end enclosing_range scip-python python snapshot-util 0.1 advanced/Test#
49+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# < definition scip-python python snapshot-util 0.1 simple/__init__:
2+
3+
# format-options: showRanges
4+
# < start enclosing_range scip-python python snapshot-util 0.1 simple/Test#
5+
class Test():
6+
# ^^^^ definition snapshot-util 0.1 simple/Test#
7+
pass
8+
# < end enclosing_range scip-python python snapshot-util 0.1 simple/Test#
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# < definition scip-python python snapshot-util 0.1 advanced/__init__:
2+
3+
# format-options: showRanges
4+
# < start enclosing_range scip-python python snapshot-util 0.1 advanced/decorator().
5+
def decorator(func):
6+
# ^^^^^^^^^ definition snapshot-util 0.1 advanced/decorator().
7+
# ^^^^ definition snapshot-util 0.1 advanced/decorator().(func)
8+
# ⌄ start enclosing_range scip-python python snapshot-util 0.1 advanced/decorator().wrapper().
9+
def wrapper(*args, **kwargs):
10+
# ^^^^^^^ definition snapshot-util 0.1 advanced/decorator().wrapper().
11+
# ^^^^ definition snapshot-util 0.1 advanced/decorator().wrapper().(args)
12+
# ^^^^^^ definition snapshot-util 0.1 advanced/decorator().wrapper().(kwargs)
13+
return func(*args, **kwargs)
14+
# ^^^^ reference snapshot-util 0.1 advanced/decorator().(func)
15+
# ^^^^ reference snapshot-util 0.1 advanced/decorator().wrapper().(args)
16+
# ^^^^^^ reference snapshot-util 0.1 advanced/decorator().wrapper().(kwargs)
17+
# ^ end enclosing_range scip-python python snapshot-util 0.1 advanced/decorator().wrapper().
18+
return wrapper
19+
# ^^^^^^^ reference snapshot-util 0.1 advanced/decorator().wrapper().
20+
# < end enclosing_range scip-python python snapshot-util 0.1 advanced/decorator().
21+
22+
# < start enclosing_range scip-python python snapshot-util 0.1 advanced/func().
23+
@decorator
24+
#^^^^^^^^^ reference snapshot-util 0.1 advanced/decorator().
25+
def func(x: float) -> float:
26+
# ^^^^ definition snapshot-util 0.1 advanced/func().
27+
# ^ definition snapshot-util 0.1 advanced/func().(x)
28+
# ^^^^^ reference python-stdlib 3.11 builtins/float#
29+
# ^^^^^ reference python-stdlib 3.11 builtins/float#
30+
test = x
31+
# ^^^^ definition local 0
32+
# ^ reference snapshot-util 0.1 advanced/func().(x)
33+
34+
return test
35+
# ^^^^ reference local 0
36+
# < end enclosing_range scip-python python snapshot-util 0.1 advanced/func().
37+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# < definition scip-python python snapshot-util 0.1 simple/__init__:
2+
3+
# format-options: showRanges
4+
# < start enclosing_range scip-python python snapshot-util 0.1 simple/simple().
5+
def simple(x):
6+
# ^^^^^^ definition snapshot-util 0.1 simple/simple().
7+
# ^ definition snapshot-util 0.1 simple/simple().(x)
8+
return x
9+
# ^ reference snapshot-util 0.1 simple/simple().(x)
10+
# < end enclosing_range scip-python python snapshot-util 0.1 simple/simple().
11+
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
# < definition scip-python python snapshot-util 0.1 fstring/__init__:
2-
#documentation (module) fstring
32

43
var = ", world!"
54
#^^ definition snapshot-util 0.1 fstring/var.
6-
#documentation ```python
7-
# > builtins.str
8-
# > ```
95

106
print(f"var: hello {var}")
117
#^^^^ reference python-stdlib 3.11 builtins/print().
12-
#external documentation ```python
13-
# > (function) def print(
14-
# > *values: object,
15-
# > sep: str | None = " ",
16-
# > end: str | None = "\n",
17-
# > file: SupportsWrite[str] | None = No...
18-
# > flush: Literal[False] = False
19-
# > ) -> None
20-
# > ```
218
# ^^^ reference snapshot-util 0.1 fstring/var.
229

Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
# < definition scip-python python snapshot-util 0.1 `abc.file`/__init__:
2-
#documentation (module) abc.file
32

43
from xyz import nested_file
54
# ^^^ reference snapshot-util 0.1 xyz/__init__:
65
# ^^^^^^^^^^^ reference snapshot-util 0.1 `xyz.nested_file`/__init__:
76

87
print(nested_file.X)
98
#^^^^ reference python-stdlib 3.11 builtins/print().
10-
#external documentation ```python
11-
# > (function) def print(
12-
# > *values: object,
13-
# > sep: str | None = " ",
14-
# > end: str | None = "\n",
15-
# > file: SupportsWrite[str] | None = No...
16-
# > flush: Literal[False] = False
17-
# > ) -> None
18-
# > ```
199
# ^^^^^^^^^^^ reference snapshot-util 0.1 `xyz.nested_file`/__init__:
2010
# ^ reference snapshot-util 0.1 `xyz.nested_file`/X.
2111

0 commit comments

Comments
 (0)