|
1 | 1 | """Stuff that we had to move out of its right place because of mypyc limitations.""" |
2 | 2 |
|
3 | 3 |
|
4 | | -# Moved from util.py, because it inherits from Exception |
5 | | -class DecodeError(Exception): |
6 | | - """Exception raised when a file cannot be decoded due to an unknown encoding type. |
7 | | -
|
8 | | - Essentially a wrapper for the LookupError raised by `bytearray.decode` |
9 | | - """ |
10 | | - |
11 | | - |
12 | 4 | # Moved from types.py, because it inherits from Enum, which uses a |
13 | 5 | # metaclass in a nontrivial way. |
14 | 6 | from enum import Enum |
@@ -36,60 +28,3 @@ class TypeOfAny(Enum): |
36 | 28 | from_another_any = 'from_another_any' |
37 | 29 | # Does this Any come from an implementation limitation/bug? |
38 | 30 | implementation_artifact = 'implementation_artifact' |
39 | | - |
40 | | - |
41 | | -# Moved from nodes.py, because it inherits from dict |
42 | | -from typing import Dict, List, Any |
43 | | - |
44 | | -JsonDict = Dict[str, Any] |
45 | | - |
46 | | -MYPY = False |
47 | | -if MYPY: |
48 | | - from mypy.nodes import SymbolTableNode |
49 | | - |
50 | | - |
51 | | -class SymbolTable(Dict[str, 'SymbolTableNode']): |
52 | | - def __str__(self) -> str: |
53 | | - from mypy.nodes import implicit_module_attrs, SymbolTableNode # noqa |
54 | | - |
55 | | - a = [] # type: List[str] |
56 | | - for key, value in self.items(): |
57 | | - # Filter out the implicit import of builtins. |
58 | | - if isinstance(value, SymbolTableNode): |
59 | | - if (value.fullname != 'builtins' and |
60 | | - (value.fullname or '').split('.')[-1] not in |
61 | | - implicit_module_attrs): |
62 | | - a.append(' ' + str(key) + ' : ' + str(value)) |
63 | | - else: |
64 | | - a.append(' <invalid item>') |
65 | | - a = sorted(a) |
66 | | - a.insert(0, 'SymbolTable(') |
67 | | - a[-1] += ')' |
68 | | - return '\n'.join(a) |
69 | | - |
70 | | - def copy(self) -> 'SymbolTable': |
71 | | - return SymbolTable((key, node.copy()) |
72 | | - for key, node in self.items()) |
73 | | - |
74 | | - def serialize(self, fullname: str) -> JsonDict: |
75 | | - data = {'.class': 'SymbolTable'} # type: JsonDict |
76 | | - for key, value in self.items(): |
77 | | - # Skip __builtins__: it's a reference to the builtins |
78 | | - # module that gets added to every module by |
79 | | - # SemanticAnalyzerPass2.visit_file(), but it shouldn't be |
80 | | - # accessed by users of the module. |
81 | | - if key == '__builtins__' or value.no_serialize: |
82 | | - continue |
83 | | - data[key] = value.serialize(fullname, key) |
84 | | - return data |
85 | | - |
86 | | - @classmethod |
87 | | - def deserialize(cls, data: JsonDict) -> 'SymbolTable': |
88 | | - from mypy.nodes import SymbolTableNode # noqa |
89 | | - |
90 | | - assert data['.class'] == 'SymbolTable' |
91 | | - st = SymbolTable() |
92 | | - for key, value in data.items(): |
93 | | - if key != '.class': |
94 | | - st[key] = SymbolTableNode.deserialize(value) |
95 | | - return st |
0 commit comments