Skip to content

Commit

Permalink
Remove from_python_3 field from StrExpr (#13262)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Jul 28, 2022
1 parent 0ec789d commit 2e08ce6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 24 deletions.
6 changes: 1 addition & 5 deletions mypy/exprtotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion mypy/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 2 additions & 17 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mypy/treetransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2e08ce6

Please sign in to comment.