diff --git a/mypy/exprtotype.py b/mypy/exprtotype.py index 0c66b57a69ed..6b96fa823c0b 100644 --- a/mypy/exprtotype.py +++ b/mypy/exprtotype.py @@ -169,11 +169,7 @@ def expr_to_unanalyzed_type( ) elif isinstance(expr, StrExpr): return parse_type_string( - expr.value, - "builtins.str", - expr.line, - expr.column, - assume_str_is_unicode=expr.from_python_3, + expr.value, "builtins.str", expr.line, expr.column, assume_str_is_unicode=True ) elif isinstance(expr, BytesExpr): return parse_type_string( diff --git a/mypy/literals.py b/mypy/literals.py index 1520c92cdd87..a34543bbed7f 100644 --- a/mypy/literals.py +++ b/mypy/literals.py @@ -140,7 +140,7 @@ def visit_int_expr(self, e: IntExpr) -> Key: return ("Literal", e.value) def visit_str_expr(self, e: StrExpr) -> Key: - return ("Literal", e.value, e.from_python_3) + return ("Literal", e.value) def visit_bytes_expr(self, e: BytesExpr) -> Key: return ("Literal", e.value) diff --git a/mypy/nodes.py b/mypy/nodes.py index 3da5dc6ee1e9..690dca595452 100644 --- a/mypy/nodes.py +++ b/mypy/nodes.py @@ -1568,28 +1568,13 @@ def accept(self, visitor: ExpressionVisitor[T]) -> T: class StrExpr(Expression): """String literal""" - __slots__ = ("value", "from_python_3") + __slots__ = ("value",) value: str # '' by default - # Keeps track of whether this string originated from Python 2 source code vs - # Python 3 source code. We need to keep track of this information so we can - # correctly handle types that have "nested strings". For example, consider this - # type alias, where we have a forward reference to a literal type: - # - # Alias = List["Literal['foo']"] - # - # When parsing this, we need to know whether the outer string and alias came from - # Python 2 code vs Python 3 code so we can determine whether the inner `Literal['foo']` - # is meant to be `Literal[u'foo']` or `Literal[b'foo']`. - # - # This field keeps track of that information. - from_python_3: bool - - def __init__(self, value: str, from_python_3: bool = False) -> None: + def __init__(self, value: str) -> None: super().__init__() self.value = value - self.from_python_3 = from_python_3 def accept(self, visitor: ExpressionVisitor[T]) -> T: return visitor.visit_str_expr(self) diff --git a/mypy/treetransform.py b/mypy/treetransform.py index 422a99af00da..0bf2213bf406 100644 --- a/mypy/treetransform.py +++ b/mypy/treetransform.py @@ -386,7 +386,7 @@ def visit_int_expr(self, node: IntExpr) -> IntExpr: return IntExpr(node.value) def visit_str_expr(self, node: StrExpr) -> StrExpr: - return StrExpr(node.value, node.from_python_3) + return StrExpr(node.value) def visit_bytes_expr(self, node: BytesExpr) -> BytesExpr: return BytesExpr(node.value)