Skip to content

Commit 4a603eb

Browse files
Merge branch 'master' into test-range
2 parents 3aaa661 + c6b40df commit 4a603eb

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@
278278
intersphinx_mapping = {
279279
"python": ("https://docs.python.org/3", None),
280280
"attrs": ("https://www.attrs.org/en/stable/", None),
281-
"cython": ("https://docs.cython.org/en/latest", None),
281+
"cython": ("https://cython.readthedocs.io/en/stable", None),
282282
"monkeytype": ("https://monkeytype.readthedocs.io/en/latest", None),
283-
"setuptools": ("https://setuptools.readthedocs.io/en/latest", None),
283+
"setuptools": ("https://setuptools.pypa.io/en/latest", None),
284284
}
285285

286286

mypy/checker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5577,6 +5577,8 @@ def infer_variable_types_from_type_maps(
55775577
previous_type, _, _ = self.check_lvalue(expr)
55785578
if previous_type is not None:
55795579
already_exists = True
5580+
if isinstance(expr.node, Var) and expr.node.is_final:
5581+
self.msg.cant_assign_to_final(expr.name, False, expr)
55805582
if self.check_subtype(
55815583
typ,
55825584
previous_type,

mypy/checkexpr.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3468,7 +3468,7 @@ def visit_op_expr(self, e: OpExpr) -> Type:
34683468
# It's actually a type expression X | Y.
34693469
return self.accept(e.analyzed)
34703470
if e.op == "and" or e.op == "or":
3471-
return self.check_boolean_op(e, e)
3471+
return self.check_boolean_op(e)
34723472
if e.op == "*" and isinstance(e.left, ListExpr):
34733473
# Expressions of form [...] * e get special type inference.
34743474
return self.check_list_multiply(e)
@@ -4255,20 +4255,18 @@ def check_op(
42554255
context=context,
42564256
)
42574257

4258-
def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
4258+
def check_boolean_op(self, e: OpExpr) -> Type:
42594259
"""Type check a boolean operation ('and' or 'or')."""
42604260

42614261
# A boolean operation can evaluate to either of the operands.
42624262

4263-
# We use the current type context to guide the type inference of of
4263+
# We use the current type context to guide the type inference of
42644264
# the left operand. We also use the left operand type to guide the type
42654265
# inference of the right operand so that expressions such as
42664266
# '[1] or []' are inferred correctly.
42674267
ctx = self.type_context[-1]
42684268
left_type = self.accept(e.left, ctx)
4269-
expanded_left_type = try_expanding_sum_type_to_union(
4270-
self.accept(e.left, ctx), "builtins.bool"
4271-
)
4269+
expanded_left_type = try_expanding_sum_type_to_union(left_type, "builtins.bool")
42724270

42734271
assert e.op in ("and", "or") # Checked by visit_op_expr
42744272

test-data/unit/check-python310.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2839,3 +2839,13 @@ match value_type:
28392839
case _:
28402840
assert_never(value_type)
28412841
[builtins fixtures/tuple.pyi]
2842+
2843+
[case testAssignmentToFinalInMatchCaseNotAllowed]
2844+
from typing import Final
2845+
2846+
FOO: Final[int] = 10
2847+
2848+
val: int = 8
2849+
match val:
2850+
case FOO: # E: Cannot assign to final name "FOO"
2851+
pass

0 commit comments

Comments
 (0)