Merge pull request #2970 from continuedev/tomasz/python
Capture python definitions
This commit is contained in:
commit
1ec789788c
14 changed files with 318 additions and 90 deletions
|
|
@ -1,30 +1,9 @@
|
|||
import { TYPESCRIPT_TEST_CASES } from "./testCases/typescript";
|
||||
import { PYTHON_TEST_CASES, TYPESCRIPT_TEST_CASES } from "./testCases";
|
||||
import { testRootPathContext } from "./testUtils";
|
||||
|
||||
const TEST_CASES = [
|
||||
...PYTHON_TEST_CASES,
|
||||
...TYPESCRIPT_TEST_CASES,
|
||||
{
|
||||
nodeType: "function_definition",
|
||||
fileName: "file1.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 4, character: 25 },
|
||||
definitionPositions: [
|
||||
{ row: 3, column: 30 }, // Person
|
||||
{ row: 3, column: 42 }, // Address
|
||||
],
|
||||
},
|
||||
{
|
||||
nodeType: "function_definition (inside a class)",
|
||||
fileName: "file1.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 12, character: 33 },
|
||||
definitionPositions: [
|
||||
{ row: 6, column: 21 }, // BaseClass
|
||||
{ row: 6, column: 33 }, // Collection
|
||||
{ row: 11, column: 47 }, // Person
|
||||
{ row: 11, column: 59 }, // Address
|
||||
],
|
||||
},
|
||||
{
|
||||
nodeType: "function_definition",
|
||||
fileName: "file1.php",
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
from .base_module import BaseClass, Collection, Person, Address
|
||||
from typing import List
|
||||
|
||||
def get_address(person: Person) -> Address:
|
||||
return person.address
|
||||
|
||||
class Group(BaseClass, Collection):
|
||||
def __init__(self, people: List[Person]) -> None:
|
||||
super().__init__()
|
||||
self.people = people
|
||||
|
||||
def get_person_address(self, person: Person) -> Address:
|
||||
return get_address(person)
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
class Group(BaseClass, Person):
|
||||
pass
|
||||
|
||||
class Group(metaclass=MetaGroup):
|
||||
pass
|
||||
|
||||
class Group(BaseClass[Address], Gathering[Person]):
|
||||
pass
|
||||
|
||||
class Group(List[Address], Person[str]):
|
||||
pass
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
from typing import List, Union, TypeVar, Generic
|
||||
|
||||
T = TypeVar('T')
|
||||
|
||||
class Address:
|
||||
pass
|
||||
|
||||
class Person:
|
||||
pass
|
||||
|
||||
class PersonWithGeneric(Generic[T]):
|
||||
pass
|
||||
|
||||
|
||||
def get_address(person: Person) -> Address:
|
||||
pass
|
||||
|
||||
def get_group_address(people: Group[Person]) -> Group[Address]:
|
||||
pass
|
||||
|
||||
def log_person(person: Person) -> None:
|
||||
pass
|
||||
|
||||
def get_hardcoded_address() -> Address:
|
||||
pass
|
||||
|
||||
def log_person_or_address(value: Union[Person, Address]) -> Union[Person, Address]:
|
||||
pass
|
||||
|
||||
def log_person_and_address(person: Person, address: Address) -> None:
|
||||
pass
|
||||
|
||||
def get_address_generator(person: Person) -> Generator[Address, None, None]:
|
||||
yield
|
||||
|
||||
|
||||
class Group:
|
||||
def log_person_and_address(self, person: Person, address: Address) -> None:
|
||||
pass
|
||||
|
||||
async def get_person(address: Address) -> Person:
|
||||
pass
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export * from "./python";
|
||||
export * from "./typescript";
|
||||
|
|
@ -0,0 +1,145 @@
|
|||
export const FUNCTIONS = [
|
||||
{
|
||||
nodeType: "function_definition with argument and return type",
|
||||
fileName: "python/functions.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 15, character: 8 },
|
||||
definitionPositions: [
|
||||
{ row: 14, column: 30 }, // Person
|
||||
{ row: 14, column: 42 }, // Address
|
||||
],
|
||||
},
|
||||
{
|
||||
nodeType:
|
||||
"function_definition with generic argument and generic return type",
|
||||
fileName: "python/functions.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 18, character: 8 },
|
||||
definitionPositions: [
|
||||
{ row: 17, column: 35 }, // Group
|
||||
{ row: 17, column: 42 }, // Person
|
||||
{ row: 17, column: 53 }, // Group
|
||||
{ row: 17, column: 61 }, // Address
|
||||
],
|
||||
},
|
||||
{
|
||||
nodeType: "function_definition with single argument and None return type",
|
||||
fileName: "python/functions.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 21, character: 8 },
|
||||
definitionPositions: [
|
||||
{ row: 20, column: 29 }, // Person
|
||||
],
|
||||
},
|
||||
{
|
||||
nodeType: "function_definition with no arguments and single return type",
|
||||
fileName: "python/functions.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 24, character: 8 },
|
||||
definitionPositions: [
|
||||
{ row: 23, column: 38 }, // Address
|
||||
],
|
||||
},
|
||||
{
|
||||
nodeType: "function_definition with Union arguments and Union return type",
|
||||
fileName: "python/functions.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 27, character: 8 },
|
||||
definitionPositions: [
|
||||
{ row: 26, column: 45 }, // Person
|
||||
{ row: 26, column: 54 }, // Address
|
||||
{ row: 26, column: 72 }, // Person
|
||||
{ row: 26, column: 81 }, // Address
|
||||
],
|
||||
},
|
||||
{
|
||||
nodeType:
|
||||
"function_definition with multiple arguments and None return type",
|
||||
fileName: "python/functions.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 30, character: 8 },
|
||||
definitionPositions: [
|
||||
{ row: 29, column: 41 }, // Person
|
||||
{ row: 29, column: 59 }, // Address
|
||||
],
|
||||
},
|
||||
{
|
||||
nodeType: "function_definition with one argument and Generator return type",
|
||||
fileName: "python/functions.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 33, character: 9 },
|
||||
definitionPositions: [
|
||||
{ row: 32, column: 40 }, // Person
|
||||
{ row: 32, column: 62 }, // Address
|
||||
],
|
||||
},
|
||||
{
|
||||
nodeType: "function_definition inside a class",
|
||||
fileName: "python/functions.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 38, character: 12 },
|
||||
definitionPositions: [
|
||||
{ row: 37, column: 51 }, // Person
|
||||
{ row: 37, column: 69 }, // Address
|
||||
],
|
||||
},
|
||||
{
|
||||
nodeType: "function_definition of an async function",
|
||||
fileName: "python/functions.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 41, character: 8 },
|
||||
definitionPositions: [
|
||||
{ row: 40, column: 37 }, // Address
|
||||
{ row: 40, column: 48 }, // Person
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export const CLASSES = [
|
||||
{
|
||||
nodeType: "class_definition with multiple superclasses",
|
||||
fileName: "python/classes.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 1, character: 8 },
|
||||
definitionPositions: [
|
||||
{ row: 0, column: 21 }, // BaseClass
|
||||
{ row: 0, column: 29 }, // Person
|
||||
],
|
||||
},
|
||||
{
|
||||
nodeType: "class_definition with multiple superclasses",
|
||||
fileName: "python/classes.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 4, character: 8 },
|
||||
definitionPositions: [
|
||||
{ row: 3, column: 31 }, // MetaGroup
|
||||
],
|
||||
},
|
||||
{
|
||||
nodeType: "class_definition with generic superclasses",
|
||||
fileName: "python/classes.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 7, character: 8 },
|
||||
definitionPositions: [
|
||||
{ row: 6, column: 21 }, // BaseClass
|
||||
{ row: 6, column: 29 }, // Address
|
||||
{ row: 6, column: 41 }, // Gathering
|
||||
{ row: 6, column: 48 }, // Person
|
||||
],
|
||||
},
|
||||
{
|
||||
nodeType: "class_definition with generic superclasses (built in types)",
|
||||
fileName: "python/classes.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 10, character: 8 },
|
||||
definitionPositions: [
|
||||
{ row: 9, column: 24 }, // Address
|
||||
{ row: 9, column: 33 }, // Person
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export const PYTHON_TEST_CASES = [
|
||||
// ...FUNCTIONS,
|
||||
...CLASSES,
|
||||
];
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
const FUNCTIONS = [
|
||||
{
|
||||
nodeType: "function_declaration with a param and a return type",
|
||||
fileName: "functions.ts",
|
||||
fileName: "typescript/functions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 3, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -11,7 +11,7 @@ const FUNCTIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "function_declaration with array param",
|
||||
fileName: "functions.ts",
|
||||
fileName: "typescript/functions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 7, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -21,7 +21,7 @@ const FUNCTIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "function_declaration without return type",
|
||||
fileName: "functions.ts",
|
||||
fileName: "typescript/functions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 11, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -30,7 +30,7 @@ const FUNCTIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "function_declaration without params",
|
||||
fileName: "functions.ts",
|
||||
fileName: "typescript/functions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 15, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -39,7 +39,7 @@ const FUNCTIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "function_declaration with array params and array return type",
|
||||
fileName: "functions.ts",
|
||||
fileName: "typescript/functions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 19, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -50,7 +50,7 @@ const FUNCTIONS = [
|
|||
{
|
||||
nodeType:
|
||||
"function_declaration with generic params and generic return type",
|
||||
fileName: "functions.ts",
|
||||
fileName: "typescript/functions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 23, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -63,7 +63,7 @@ const FUNCTIONS = [
|
|||
{
|
||||
nodeType:
|
||||
"function_declaration with union type params and union return type",
|
||||
fileName: "functions.ts",
|
||||
fileName: "typescript/functions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 27, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -75,7 +75,7 @@ const FUNCTIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "function_declaration with two arguments",
|
||||
fileName: "functions.ts",
|
||||
fileName: "typescript/functions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 31, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -88,7 +88,7 @@ const FUNCTIONS = [
|
|||
const GENERATORS = [
|
||||
{
|
||||
nodeType: "function_declaration with a param and a return type",
|
||||
fileName: "generators.ts",
|
||||
fileName: "typescript/generators.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 3, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -98,7 +98,7 @@ const GENERATORS = [
|
|||
},
|
||||
{
|
||||
nodeType: "function_declaration with array param",
|
||||
fileName: "generators.ts",
|
||||
fileName: "typescript/generators.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 7, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -108,7 +108,7 @@ const GENERATORS = [
|
|||
},
|
||||
{
|
||||
nodeType: "function_declaration without return type",
|
||||
fileName: "generators.ts",
|
||||
fileName: "typescript/generators.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 11, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -117,7 +117,7 @@ const GENERATORS = [
|
|||
},
|
||||
{
|
||||
nodeType: "function_declaration without params",
|
||||
fileName: "generators.ts",
|
||||
fileName: "typescript/generators.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 15, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -126,7 +126,7 @@ const GENERATORS = [
|
|||
},
|
||||
{
|
||||
nodeType: "function_declaration with array params and array return type",
|
||||
fileName: "generators.ts",
|
||||
fileName: "typescript/generators.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 19, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -137,7 +137,7 @@ const GENERATORS = [
|
|||
{
|
||||
nodeType:
|
||||
"function_declaration with generic params and generic return type",
|
||||
fileName: "generators.ts",
|
||||
fileName: "typescript/generators.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 23, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -150,7 +150,7 @@ const GENERATORS = [
|
|||
{
|
||||
nodeType:
|
||||
"function_declaration with union type params and union return type",
|
||||
fileName: "generators.ts",
|
||||
fileName: "typescript/generators.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 27, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -162,7 +162,7 @@ const GENERATORS = [
|
|||
},
|
||||
{
|
||||
nodeType: "function_declaration with two arguments",
|
||||
fileName: "generators.ts",
|
||||
fileName: "typescript/generators.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 31, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -175,7 +175,7 @@ const GENERATORS = [
|
|||
const ARROW_FUNCTIONS = [
|
||||
{
|
||||
nodeType: "arrow_function with a param and a return type",
|
||||
fileName: "arrowFunctions.ts",
|
||||
fileName: "typescript/arrowFunctions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 3, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -185,7 +185,7 @@ const ARROW_FUNCTIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "arrow_function without return type",
|
||||
fileName: "arrowFunctions.ts",
|
||||
fileName: "typescript/arrowFunctions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 7, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -194,7 +194,7 @@ const ARROW_FUNCTIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "arrow_function without params",
|
||||
fileName: "arrowFunctions.ts",
|
||||
fileName: "typescript/arrowFunctions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 11, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -203,7 +203,7 @@ const ARROW_FUNCTIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "arrow_function with array params and array return type",
|
||||
fileName: "arrowFunctions.ts",
|
||||
fileName: "typescript/arrowFunctions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 15, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -213,7 +213,7 @@ const ARROW_FUNCTIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "arrow_function with generic params and generic return type",
|
||||
fileName: "arrowFunctions.ts",
|
||||
fileName: "typescript/arrowFunctions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 19, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -225,7 +225,7 @@ const ARROW_FUNCTIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "arrow_function with union type params and union return type",
|
||||
fileName: "arrowFunctions.ts",
|
||||
fileName: "typescript/arrowFunctions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 23, character: 9 },
|
||||
definitionPositions: [
|
||||
|
|
@ -237,7 +237,7 @@ const ARROW_FUNCTIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "arrow_function with two arguments",
|
||||
fileName: "arrowFunctions.ts",
|
||||
fileName: "typescript/arrowFunctions.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 27, character: 11 },
|
||||
definitionPositions: [
|
||||
|
|
@ -250,7 +250,7 @@ const ARROW_FUNCTIONS = [
|
|||
const CLASS_METHODS = [
|
||||
{
|
||||
nodeType: "method_declaration with a param and a return type",
|
||||
fileName: "classMethods.ts",
|
||||
fileName: "typescript/classMethods.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 4, character: 11 },
|
||||
definitionPositions: [
|
||||
|
|
@ -260,7 +260,7 @@ const CLASS_METHODS = [
|
|||
},
|
||||
{
|
||||
nodeType: "method_declaration without arguments",
|
||||
fileName: "classMethods.ts",
|
||||
fileName: "typescript/classMethods.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 8, character: 11 },
|
||||
definitionPositions: [
|
||||
|
|
@ -269,7 +269,7 @@ const CLASS_METHODS = [
|
|||
},
|
||||
{
|
||||
nodeType: "method_declaration without return type",
|
||||
fileName: "classMethods.ts",
|
||||
fileName: "typescript/classMethods.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 12, character: 11 },
|
||||
definitionPositions: [
|
||||
|
|
@ -278,7 +278,7 @@ const CLASS_METHODS = [
|
|||
},
|
||||
{
|
||||
nodeType: "method_declaration with array type arguments",
|
||||
fileName: "classMethods.ts",
|
||||
fileName: "typescript/classMethods.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 16, character: 11 },
|
||||
definitionPositions: [
|
||||
|
|
@ -288,7 +288,7 @@ const CLASS_METHODS = [
|
|||
{
|
||||
nodeType:
|
||||
"method_declaration with array type arguments and array type return",
|
||||
fileName: "classMethods.ts",
|
||||
fileName: "typescript/classMethods.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 20, character: 11 },
|
||||
definitionPositions: [
|
||||
|
|
@ -299,7 +299,7 @@ const CLASS_METHODS = [
|
|||
{
|
||||
nodeType:
|
||||
"method_declaration with with generic params and generic return type",
|
||||
fileName: "classMethods.ts",
|
||||
fileName: "typescript/classMethods.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 24, character: 11 },
|
||||
definitionPositions: [
|
||||
|
|
@ -311,7 +311,7 @@ const CLASS_METHODS = [
|
|||
},
|
||||
{
|
||||
nodeType: "method_declaration with union type params and union return type",
|
||||
fileName: "classMethods.ts",
|
||||
fileName: "typescript/classMethods.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 28, character: 11 },
|
||||
definitionPositions: [
|
||||
|
|
@ -323,7 +323,7 @@ const CLASS_METHODS = [
|
|||
},
|
||||
{
|
||||
nodeType: "method_declaration with two arguments",
|
||||
fileName: "classMethods.ts",
|
||||
fileName: "typescript/classMethods.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 32, character: 11 },
|
||||
definitionPositions: [
|
||||
|
|
@ -336,7 +336,7 @@ const CLASS_METHODS = [
|
|||
const CLASS_DEFINITIONS = [
|
||||
{
|
||||
nodeType: "class_declaration with base class",
|
||||
fileName: "classes.ts",
|
||||
fileName: "typescript/classes.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 2, character: 31 },
|
||||
definitionPositions: [
|
||||
|
|
@ -345,7 +345,7 @@ const CLASS_DEFINITIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "class_declaration with interface",
|
||||
fileName: "classes.ts",
|
||||
fileName: "typescript/classes.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 4, character: 39 },
|
||||
definitionPositions: [
|
||||
|
|
@ -354,7 +354,7 @@ const CLASS_DEFINITIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "class_declaration with base class and multiple interfaces",
|
||||
fileName: "classes.ts",
|
||||
fileName: "typescript/classes.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 6, character: 74 },
|
||||
definitionPositions: [
|
||||
|
|
@ -365,7 +365,7 @@ const CLASS_DEFINITIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "class_declaration with base class and multiple interfaces",
|
||||
fileName: "classes.ts",
|
||||
fileName: "typescript/classes.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 6, character: 74 },
|
||||
definitionPositions: [
|
||||
|
|
@ -376,7 +376,7 @@ const CLASS_DEFINITIONS = [
|
|||
},
|
||||
{
|
||||
nodeType: "class_declaration with generic base class and generic interface",
|
||||
fileName: "classes.ts",
|
||||
fileName: "typescript/classes.ts",
|
||||
language: "TypeScript",
|
||||
cursorPosition: { line: 8, character: 69 },
|
||||
definitionPositions: [
|
||||
|
|
|
|||
|
|
@ -1,5 +1,24 @@
|
|||
(
|
||||
(class_definition
|
||||
superclasses: (argument_list
|
||||
(identifier) @superclass))
|
||||
; Match superclass identifiers in a simple inheritance
|
||||
(class_definition
|
||||
superclasses: (argument_list
|
||||
(identifier) @catch)
|
||||
(#not-match? @catch "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$")
|
||||
)
|
||||
|
||||
; Match the value of a keyword argument in class inheritance
|
||||
(class_definition
|
||||
superclasses: (argument_list
|
||||
(keyword_argument
|
||||
(_)
|
||||
(identifier) @catch))
|
||||
(#not-match? @catch "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$")
|
||||
)
|
||||
|
||||
; Match identifiers within subscripts in class inheritance
|
||||
(class_definition
|
||||
superclasses: (argument_list
|
||||
(subscript
|
||||
(identifier) @catch
|
||||
))
|
||||
(#not-match? @catch "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$")
|
||||
)
|
||||
|
|
@ -1,17 +1,60 @@
|
|||
(
|
||||
(function_definition
|
||||
(parameters
|
||||
(_
|
||||
(type) @a
|
||||
(#not-match? @a "^(str|int|float|bool|list|dict|tuple)$")
|
||||
)
|
||||
)
|
||||
)
|
||||
; When the type is a simple identifier:
|
||||
(function_definition
|
||||
parameters: (parameters
|
||||
(typed_parameter
|
||||
type: (type
|
||||
(identifier) @type_identifier)))
|
||||
|
||||
(#not-match? @type_identifier "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$")
|
||||
)
|
||||
|
||||
(
|
||||
(function_definition
|
||||
(type) @b
|
||||
(#not-match? @b "^(str|int|float|bool|list|dict|tuple)$")
|
||||
)
|
||||
; When the type is a generic type with one identifier
|
||||
(function_definition
|
||||
parameters: (parameters
|
||||
(typed_parameter
|
||||
type: (type
|
||||
(generic_type
|
||||
(identifier) @type_identifier))))
|
||||
|
||||
(#not-match? @type_identifier "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$")
|
||||
)
|
||||
|
||||
; When the generic type has type parameters with one identifier
|
||||
(function_definition
|
||||
parameters: (parameters
|
||||
(typed_parameter
|
||||
type: (type
|
||||
(generic_type
|
||||
(identifier)
|
||||
(type_parameter
|
||||
(type
|
||||
(identifier) @type_identifier))))))
|
||||
|
||||
(#not-match? @type_identifier "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$")
|
||||
)
|
||||
|
||||
; When the return type is a simple identifier
|
||||
(function_definition
|
||||
return_type: (type
|
||||
(identifier) @type_identifier)
|
||||
(#not-match? @type_identifier "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$")
|
||||
)
|
||||
|
||||
; When the return type is a generic type with one identifier
|
||||
(function_definition
|
||||
return_type: (type
|
||||
(generic_type
|
||||
(identifier) @type_identifier))
|
||||
(#not-match? @type_identifier "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$")
|
||||
)
|
||||
|
||||
; When the generic type has type parameters with one identifier
|
||||
(function_definition
|
||||
return_type: (type
|
||||
(generic_type
|
||||
(identifier)
|
||||
(type_parameter
|
||||
(type
|
||||
(identifier) @type_identifier))))
|
||||
(#not-match? @type_identifier "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$")
|
||||
)
|
||||
Loading…
Add table
Reference in a new issue