Skip to content

Remove from_python_3 field from StrExpr #13262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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