예제 #1
0
파일: options.py 프로젝트: ykursav/mypy
 def apply_changes(self, changes: Dict[str, object]) -> 'Options':
     new_options = Options()
     # Under mypyc, we don't have a __dict__, so we need to do worse things.
     replace_object_state(new_options, self, copy_dict=True)
     for key, value in changes.items():
         setattr(new_options, key, value)
     return new_options
예제 #2
0
파일: options.py 프로젝트: ilevkivskyi/mypy
 def apply_changes(self, changes: Dict[str, object]) -> 'Options':
     new_options = Options()
     # Under mypyc, we don't have a __dict__, so we need to do worse things.
     replace_object_state(new_options, self, copy_dict=True)
     for key, value in changes.items():
         setattr(new_options, key, value)
     return new_options
예제 #3
0
파일: options.py 프로젝트: parcox/mojarnik
 def apply_changes(self, changes: Dict[str, object]) -> 'Options':
     new_options = Options()
     # Under mypyc, we don't have a __dict__, so we need to do worse things.
     replace_object_state(new_options, self, copy_dict=True)
     for key, value in changes.items():
         setattr(new_options, key, value)
     if changes.get("ignore_missing_imports"):
         # This is the only option for which a per-module and a global
         # option sometimes beheave differently.
         new_options.ignore_missing_imports_per_module = True
     return new_options
예제 #4
0
def replace_nodes_in_symbol_table(symbols: SymbolTable,
                                  replacements: Dict[SymbolNode, SymbolNode]) -> None:
    for name, node in symbols.items():
        if node.node:
            if node.node in replacements:
                new = replacements[node.node]
                old = node.node
                replace_object_state(new, old)
                node.node = new
            if isinstance(node.node, (Var, TypeAlias)):
                # Handle them here just in case these aren't exposed through the AST.
                node.node.accept(NodeReplaceVisitor(replacements))
예제 #5
0
파일: astmerge.py 프로젝트: rheehot/mypy
def replace_nodes_in_symbol_table(symbols: SymbolTable,
                                  replacements: Dict[SymbolNode, SymbolNode]) -> None:
    for name, node in symbols.items():
        if node.node:
            if node.node in replacements:
                new = replacements[node.node]
                old = node.node
                replace_object_state(new, old)
                node.node = new
            if isinstance(node.node, Var):
                # Handle them here just in case these aren't exposed through the AST.
                # TODO: Is this necessary?
                fixup_var(node.node, replacements)
예제 #6
0
파일: astmerge.py 프로젝트: python/mypy
def replace_nodes_in_symbol_table(symbols: SymbolTable,
                                  replacements: Dict[SymbolNode, SymbolNode]) -> None:
    for name, node in symbols.items():
        if node.node:
            if node.node in replacements:
                new = replacements[node.node]
                old = node.node
                replace_object_state(new, old)
                node.node = new
            if isinstance(node.node, Var):
                # Handle them here just in case these aren't exposed through the AST.
                # TODO: Is this necessary?
                fixup_var(node.node, replacements)
예제 #7
0
    def visit_func_def(self, node: FuncDef) -> FuncDef:
        # Note that a FuncDef must be transformed to a FuncDef.

        # These contortions are needed to handle the case of recursive
        # references inside the function being transformed.
        # Set up placeholder nodes for references within this function
        # to other functions defined inside it.
        # Don't create an entry for this function itself though,
        # since we want self-references to point to the original
        # function if this is the top-level node we are transforming.
        init = FuncMapInitializer(self)
        for stmt in node.body.body:
            stmt.accept(init)

        new = FuncDef(node.name,
                      [self.copy_argument(arg) for arg in node.arguments],
                      self.block(node.body),
                      cast(Optional[FunctionLike], self.optional_type(node.type)))

        self.copy_function_attributes(new, node)

        new._fullname = node._fullname
        new.is_decorated = node.is_decorated
        new.is_conditional = node.is_conditional
        new.is_abstract = node.is_abstract
        new.is_static = node.is_static
        new.is_class = node.is_class
        new.is_property = node.is_property
        new.is_final = node.is_final
        new.original_def = node.original_def

        if node in self.func_placeholder_map:
            # There is a placeholder definition for this function. Replace
            # the attributes of the placeholder with those form the transformed
            # function. We know that the classes will be identical (otherwise
            # this wouldn't work).
            result = self.func_placeholder_map[node]
            replace_object_state(result, new)
            return result
        else:
            return new
예제 #8
0
    def visit_func_def(self, node: FuncDef) -> FuncDef:
        # Note that a FuncDef must be transformed to a FuncDef.

        # These contortions are needed to handle the case of recursive
        # references inside the function being transformed.
        # Set up placeholder nodes for references within this function
        # to other functions defined inside it.
        # Don't create an entry for this function itself though,
        # since we want self-references to point to the original
        # function if this is the top-level node we are transforming.
        init = FuncMapInitializer(self)
        for stmt in node.body.body:
            stmt.accept(init)

        new = FuncDef(node.name(),
                      [self.copy_argument(arg) for arg in node.arguments],
                      self.block(node.body),
                      cast(Optional[FunctionLike], self.optional_type(node.type)))

        self.copy_function_attributes(new, node)

        new._fullname = node._fullname
        new.is_decorated = node.is_decorated
        new.is_conditional = node.is_conditional
        new.is_abstract = node.is_abstract
        new.is_static = node.is_static
        new.is_class = node.is_class
        new.is_property = node.is_property
        new.is_final = node.is_final
        new.original_def = node.original_def

        if node in self.func_placeholder_map:
            # There is a placeholder definition for this function. Replace
            # the attributes of the placeholder with those form the transformed
            # function. We know that the classes will be identical (otherwise
            # this wouldn't work).
            result = self.func_placeholder_map[node]
            replace_object_state(result, new)
            return result
        else:
            return new
예제 #9
0
파일: astmerge.py 프로젝트: rheehot/mypy
 def fixup(self, node: SN) -> SN:
     if node in self.replacements:
         new = self.replacements[node]
         replace_object_state(new, node)
         return cast(SN, new)
     return node
예제 #10
0
파일: astmerge.py 프로젝트: python/mypy
 def fixup(self, node: SN) -> SN:
     if node in self.replacements:
         new = self.replacements[node]
         replace_object_state(new, node)
         return cast(SN, new)
     return node