Skip to content

Commit

Permalink
Adds enclosing ranges to function and class definitions (#132)
Browse files Browse the repository at this point in the history
Co-authored-by: Varun Gandhi <[email protected]>
  • Loading branch information
Titou325 and varungandhi-src authored Nov 21, 2023
1 parent f5e9aee commit 1572f2f
Show file tree
Hide file tree
Showing 53 changed files with 568 additions and 611 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# format-options: showDocs

import re
from typing import Callable, Optional

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# format-options: showDocs

class Example:
# Note, only y has a type hint
y: int
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# format-options: showRanges
def class_decorator(cls):
def wrapper(*args, **kwargs):
return cls(*args, **kwargs)
return wrapper

@class_decorator
class Test:
def __init__(self, x: float):
self.x = x

def test(self) -> float:
return self.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# format-options: showRanges
class Test():
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# format-options: showRanges
def decorator(func):
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
return wrapper

@decorator
def func(x: float) -> float:
test = x

return test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# format-options: showRanges
def simple(x):
return x
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# format-options: showDocs

class ClassWithField:

a: int
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# format-options: showDocs

class ClassWithInferredField:
def __init__(self, b: int):
self.b = b
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# format-options: showDocs

"""
This is a docstring for this module
"""
Expand Down
13 changes: 0 additions & 13 deletions packages/pyright-scip/snapshots/output/aliased_import/actual.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
# < definition scip-python python snapshot-util 0.1 actual/__init__:
#documentation (module) actual

import aliased
# ^^^^^^^ reference snapshot-util 0.1 aliased/__init__:
import aliased as A
# ^^^^^^^ reference snapshot-util 0.1 aliased/__init__:
# ^ reference local 0
# documentation ```python
# > (module) A
# > ```

print(A.SOME_CONSTANT)
#^^^^ reference python-stdlib 3.11 builtins/print().
#external documentation ```python
# > (function) def print(
# > *values: object,
# > sep: str | None = " ",
# > end: str | None = "\n",
# > file: SupportsWrite[str] | None = No...
# > flush: Literal[False] = False
# > ) -> None
# > ```
# ^ reference local 0
# ^^^^^^^^^^^^^ reference snapshot-util 0.1 aliased/SOME_CONSTANT.

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

SOME_CONSTANT = "Some Constant"
#^^^^^^^^^^^^ definition snapshot-util 0.1 aliased/SOME_CONSTANT.
#documentation ```python
# > builtins.str
# > ```

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# < definition scip-python python snapshot-util 0.1 builtin_imports/__init__:
#documentation (module) builtin_imports

# format-options: showDocs

import re
# ^^ reference python-stdlib 3.11 re/__init__:
from typing import Callable, Optional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# < definition scip-python python snapshot-util 0.1 class_nohint/__init__:
#documentation (module) class_nohint

# format-options: showDocs

class Example:
# ^^^^^^^ definition snapshot-util 0.1 class_nohint/Example#
# documentation ```python
Expand Down
48 changes: 0 additions & 48 deletions packages/pyright-scip/snapshots/output/comprehensions/comp.py
Original file line number Diff line number Diff line change
@@ -1,90 +1,42 @@
# < definition scip-python python snapshot-util 0.1 comp/__init__:
#documentation (module) comp

def something(x):
# ^^^^^^^^^ definition snapshot-util 0.1 comp/something().
# documentation ```python
# > def something(
# > x
# > ):
# > ```
# ^ definition snapshot-util 0.1 comp/something().(x)
return 2 * x
# ^ reference snapshot-util 0.1 comp/something().(x)

_ = [x for x in "should be local 0"]
# ^ reference local 0
# ^ definition local 0
# documentation ```python
# > (variable) x: str
# > ```
_ = [something(x) for x in "should be local 1"]
# ^^^^^^^^^ reference snapshot-util 0.1 comp/something().
# ^ reference local 1
# ^ definition local 1
# documentation ```python
# > (variable) x: str
# > ```
_ = [something(x) for x in "should be local 2" if x == "s"]
# ^^^^^^^^^ reference snapshot-util 0.1 comp/something().
# ^ reference local 2
# ^ definition local 2
# documentation ```python
# > (variable) x: str
# > ```
# ^ reference local 2
_ = {k: x for (k, x) in enumerate(range(10))}
# ^ reference local 3
# ^ reference local 4
# ^ definition local 3
# documentation ```python
# > (variable) k: int
# > ```
# ^ definition local 4
# documentation ```python
# > (variable) x: int
# > ```
# ^^^^^^^^^ reference python-stdlib 3.11 builtins/enumerate#
# external documentation ```python
# > class enumerate(
# > iterable: Iterable[int],
# > start: int = ...
# > )
# > ```
# ^^^^^ reference python-stdlib 3.11 builtins/range#
# external documentation ```python
# > class range(
# > __stop: SupportsIndex,
# > /
# > )
# > ```


asdf = (var for var in [1, 2, 3] if var % 2 == 0)
#^^^ definition snapshot-util 0.1 comp/asdf.
#documentation ```python
# > typing.Generator
# > ```
# ^^^ reference local 5
# ^^^ definition local 5
# documentation ```python
# > (variable) var: int
# > ```
# ^^^ reference local 5
for var in asdf:
# ^^^ definition snapshot-util 0.1 comp/var.
# ^^^^ reference snapshot-util 0.1 comp/asdf.
print(var)
# ^^^^^ reference python-stdlib 3.11 builtins/print().
# external documentation ```python
# > (function) def print(
# > *values: object,
# > sep: str | None = " ",
# > end: str | None = "\n",
# > file: SupportsWrite[str] | None = No...
# > flush: Literal[False] = False
# > ) -> None
# > ```
# ^^^ reference snapshot-util 0.1 comp/var.

# TODO: ListComprehensions with if
Expand Down
13 changes: 0 additions & 13 deletions packages/pyright-scip/snapshots/output/dunder_vars/__main__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
# < definition scip-python python snapshot-util 0.1 __main__/__init__:
#documentation (module) __main__


if __name__ == '__main__':
# ^^^^^^^^ reference python-stdlib 3.11 builtins/__name__#
# external documentation ```python
# > __name__: str
# > ```
print("main")
# ^^^^^ reference python-stdlib 3.11 builtins/print().
# external documentation ```python
# > (function) def print(
# > *values: object,
# > sep: str | None = " ",
# > end: str | None = "\n",
# > file: SupportsWrite[str] | None = No...
# > flush: Literal[False] = False
# > ) -> None
# > ```


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

def main():
# ^^^^ definition . . main/main().
# documentation ```python
# > def main(): # -> None:
# > ```
pass

main()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# < definition scip-python python snapshot-util 0.1 advanced/__init__:

# format-options: showRanges
# < start enclosing_range scip-python python snapshot-util 0.1 advanced/class_decorator().
def class_decorator(cls):
# ^^^^^^^^^^^^^^^ definition snapshot-util 0.1 advanced/class_decorator().
# ^^^ definition snapshot-util 0.1 advanced/class_decorator().(cls)
# ⌄ start enclosing_range scip-python python snapshot-util 0.1 advanced/class_decorator().wrapper().
def wrapper(*args, **kwargs):
# ^^^^^^^ definition snapshot-util 0.1 advanced/class_decorator().wrapper().
# ^^^^ definition snapshot-util 0.1 advanced/class_decorator().wrapper().(args)
# ^^^^^^ definition snapshot-util 0.1 advanced/class_decorator().wrapper().(kwargs)
return cls(*args, **kwargs)
# ^^^ reference snapshot-util 0.1 advanced/class_decorator().(cls)
# ^^^^ reference snapshot-util 0.1 advanced/class_decorator().wrapper().(args)
# ^^^^^^ reference snapshot-util 0.1 advanced/class_decorator().wrapper().(kwargs)
# ^ end enclosing_range scip-python python snapshot-util 0.1 advanced/class_decorator().wrapper().
return wrapper
# ^^^^^^^ reference snapshot-util 0.1 advanced/class_decorator().wrapper().
# < end enclosing_range scip-python python snapshot-util 0.1 advanced/class_decorator().

# < start enclosing_range scip-python python snapshot-util 0.1 advanced/Test#
@class_decorator
#^^^^^^^^^^^^^^^ reference snapshot-util 0.1 advanced/class_decorator().
class Test:
# ^^^^ definition snapshot-util 0.1 advanced/Test#
# ⌄ start enclosing_range scip-python python snapshot-util 0.1 advanced/Test#__init__().
def __init__(self, x: float):
# ^^^^^^^^ definition snapshot-util 0.1 advanced/Test#__init__().
# ^^^^ definition snapshot-util 0.1 advanced/Test#__init__().(self)
# ^ definition snapshot-util 0.1 advanced/Test#__init__().(x)
# ^^^^^ reference python-stdlib 3.11 builtins/float#
self.x = x
# ^^^^ reference snapshot-util 0.1 advanced/Test#__init__().(self)
# ^ definition snapshot-util 0.1 advanced/Test#x.
# ^ reference snapshot-util 0.1 advanced/Test#__init__().(x)
# ^ end enclosing_range scip-python python snapshot-util 0.1 advanced/Test#__init__().

# ⌄ start enclosing_range scip-python python snapshot-util 0.1 advanced/Test#test().
def test(self) -> float:
# ^^^^ definition snapshot-util 0.1 advanced/Test#test().
# ^^^^ definition snapshot-util 0.1 advanced/Test#test().(self)
# ^^^^^ reference python-stdlib 3.11 builtins/float#
return self.x
# ^^^^ reference snapshot-util 0.1 advanced/Test#test().(self)
# ^ reference snapshot-util 0.1 advanced/Test#x.
# ^ end enclosing_range scip-python python snapshot-util 0.1 advanced/Test#test().
# < end enclosing_range scip-python python snapshot-util 0.1 advanced/Test#

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# < definition scip-python python snapshot-util 0.1 simple/__init__:

# format-options: showRanges
# < start enclosing_range scip-python python snapshot-util 0.1 simple/Test#
class Test():
# ^^^^ definition snapshot-util 0.1 simple/Test#
pass
# < end enclosing_range scip-python python snapshot-util 0.1 simple/Test#

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# < definition scip-python python snapshot-util 0.1 advanced/__init__:

# format-options: showRanges
# < start enclosing_range scip-python python snapshot-util 0.1 advanced/decorator().
def decorator(func):
# ^^^^^^^^^ definition snapshot-util 0.1 advanced/decorator().
# ^^^^ definition snapshot-util 0.1 advanced/decorator().(func)
# ⌄ start enclosing_range scip-python python snapshot-util 0.1 advanced/decorator().wrapper().
def wrapper(*args, **kwargs):
# ^^^^^^^ definition snapshot-util 0.1 advanced/decorator().wrapper().
# ^^^^ definition snapshot-util 0.1 advanced/decorator().wrapper().(args)
# ^^^^^^ definition snapshot-util 0.1 advanced/decorator().wrapper().(kwargs)
return func(*args, **kwargs)
# ^^^^ reference snapshot-util 0.1 advanced/decorator().(func)
# ^^^^ reference snapshot-util 0.1 advanced/decorator().wrapper().(args)
# ^^^^^^ reference snapshot-util 0.1 advanced/decorator().wrapper().(kwargs)
# ^ end enclosing_range scip-python python snapshot-util 0.1 advanced/decorator().wrapper().
return wrapper
# ^^^^^^^ reference snapshot-util 0.1 advanced/decorator().wrapper().
# < end enclosing_range scip-python python snapshot-util 0.1 advanced/decorator().

# < start enclosing_range scip-python python snapshot-util 0.1 advanced/func().
@decorator
#^^^^^^^^^ reference snapshot-util 0.1 advanced/decorator().
def func(x: float) -> float:
# ^^^^ definition snapshot-util 0.1 advanced/func().
# ^ definition snapshot-util 0.1 advanced/func().(x)
# ^^^^^ reference python-stdlib 3.11 builtins/float#
# ^^^^^ reference python-stdlib 3.11 builtins/float#
test = x
# ^^^^ definition local 0
# ^ reference snapshot-util 0.1 advanced/func().(x)

return test
# ^^^^ reference local 0
# < end enclosing_range scip-python python snapshot-util 0.1 advanced/func().

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# < definition scip-python python snapshot-util 0.1 simple/__init__:

# format-options: showRanges
# < start enclosing_range scip-python python snapshot-util 0.1 simple/simple().
def simple(x):
# ^^^^^^ definition snapshot-util 0.1 simple/simple().
# ^ definition snapshot-util 0.1 simple/simple().(x)
return x
# ^ reference snapshot-util 0.1 simple/simple().(x)
# < end enclosing_range scip-python python snapshot-util 0.1 simple/simple().

13 changes: 0 additions & 13 deletions packages/pyright-scip/snapshots/output/f_string/fstring.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
# < definition scip-python python snapshot-util 0.1 fstring/__init__:
#documentation (module) fstring

var = ", world!"
#^^ definition snapshot-util 0.1 fstring/var.
#documentation ```python
# > builtins.str
# > ```

print(f"var: hello {var}")
#^^^^ reference python-stdlib 3.11 builtins/print().
#external documentation ```python
# > (function) def print(
# > *values: object,
# > sep: str | None = " ",
# > end: str | None = "\n",
# > file: SupportsWrite[str] | None = No...
# > flush: Literal[False] = False
# > ) -> None
# > ```
# ^^^ reference snapshot-util 0.1 fstring/var.

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

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

print(nested_file.X)
#^^^^ reference python-stdlib 3.11 builtins/print().
#external documentation ```python
# > (function) def print(
# > *values: object,
# > sep: str | None = " ",
# > end: str | None = "\n",
# > file: SupportsWrite[str] | None = No...
# > flush: Literal[False] = False
# > ) -> None
# > ```
# ^^^^^^^^^^^ reference snapshot-util 0.1 `xyz.nested_file`/__init__:
# ^ reference snapshot-util 0.1 `xyz.nested_file`/X.

Loading

0 comments on commit 1572f2f

Please sign in to comment.