Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/astroid/_ast.py: 81%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

16 statements  

1# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 

2# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE 

3# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt 

4 

5from __future__ import annotations 

6 

7import ast 

8from typing import Final, NamedTuple 

9 

10from astroid.const import Context 

11 

12 

13class FunctionType(NamedTuple): 

14 argtypes: list[ast.expr] 

15 returns: ast.expr 

16 

17 

18def parse_function_type_comment(type_comment: str) -> FunctionType | None: 

19 """Given a correct type comment, obtain a FunctionType object.""" 

20 func_type = ast.parse(type_comment, "<type_comment>", "func_type") 

21 return FunctionType(argtypes=func_type.argtypes, returns=func_type.returns) 

22 

23 

24UNARY_OP_CLASSES: Final[dict[type[ast.unaryop], str]] = { 

25 ast.UAdd: "+", 

26 ast.USub: "-", 

27 ast.Not: "not", 

28 ast.Invert: "~", 

29} 

30 

31BIN_OP_CLASSES: Final[dict[type[ast.operator], str]] = { 

32 ast.Add: "+", 

33 ast.BitAnd: "&", 

34 ast.BitOr: "|", 

35 ast.BitXor: "^", 

36 ast.Div: "/", 

37 ast.FloorDiv: "//", 

38 ast.MatMult: "@", 

39 ast.Mod: "%", 

40 ast.Mult: "*", 

41 ast.Pow: "**", 

42 ast.Sub: "-", 

43 ast.LShift: "<<", 

44 ast.RShift: ">>", 

45} 

46 

47BOOL_OP_CLASSES: Final[dict[type[ast.boolop], str]] = { 

48 ast.And: "and", 

49 ast.Or: "or", 

50} 

51 

52CMP_OP_CLASSES: Final[dict[type[ast.cmpop], str]] = { 

53 ast.Eq: "==", 

54 ast.Gt: ">", 

55 ast.GtE: ">=", 

56 ast.In: "in", 

57 ast.Is: "is", 

58 ast.IsNot: "is not", 

59 ast.Lt: "<", 

60 ast.LtE: "<=", 

61 ast.NotEq: "!=", 

62 ast.NotIn: "not in", 

63} 

64 

65CONTEXT_CLASSES: Final[dict[type[ast.expr_context], Context]] = { 

66 ast.Load: Context.Load, 

67 ast.Store: Context.Store, 

68 ast.Del: Context.Del, 

69}