コード例 #1
0
ファイル: fastparse.py プロジェクト: tony/mypy
 def visit_Str(self, n: ast35.Str) -> Node:
     if self.pyversion[0] >= 3 or self.is_stub:
         # Hack: assume all string literals in Python 2 stubs are normal
         # strs (i.e. not unicode).  All stubs are parsed with the Python 3
         # parser, which causes unprefixed string literals to be interpreted
         # as unicode instead of bytes.  This hack is generally okay,
         # because mypy considers str literals to be compatible with
         # unicode.
         return StrExpr(n.s)
     else:
         return UnicodeExpr(n.s)
コード例 #2
0
ファイル: fastparse2.py プロジェクト: smalias/mypy
 def visit_Str(self, s: ast27.Str) -> Expression:
     # Hack: assume all string literals in Python 2 stubs are normal
     # strs (i.e. not unicode).  All stubs are parsed with the Python 3
     # parser, which causes unprefixed string literals to be interpreted
     # as unicode instead of bytes.  This hack is generally okay,
     # because mypy considers str literals to be compatible with
     # unicode.
     if isinstance(s.s, bytes):
         n = s.s
         # The following line is a bit hacky, but is the best way to maintain
         # compatibility with how mypy currently parses the contents of bytes literals.
         contents = str(n)[2:-1]
         return StrExpr(contents)
     else:
         return UnicodeExpr(s.s)
コード例 #3
0
ファイル: fastparse2.py プロジェクト: pbasista/mypy
 def visit_Str(self, n: ast27.Str) -> Expression:
     # Note: typed_ast.ast27 will handled unicode_literals for us. If
     # n.s is of type 'bytes', we know unicode_literals was not enabled;
     # otherwise we know it was.
     #
     # Note that the following code is NOT run when parsing Python 2.7 stubs:
     # we always parse stub files (no matter what version) using the Python 3
     # parser. This is also why string literals in Python 2.7 stubs are assumed
     # to be unicode.
     if isinstance(n.s, bytes):
         contents = bytes_to_human_readable_repr(n.s)
         e = StrExpr(contents, from_python_3=False)  # type: Union[StrExpr, UnicodeExpr]
         return self.set_line(e, n)
     else:
         e = UnicodeExpr(n.s)
         return self.set_line(e, n)
コード例 #4
0
 def visit_unicode_expr(self, node: UnicodeExpr) -> Node:
     return UnicodeExpr(node.value)