MCPcopy Index your code
hub / github.com/python/mypy / process_final_in_overload

Method process_final_in_overload

mypy/semanal.py:1530–1547  ·  view source on GitHub ↗

Detect the @final status of an overloaded function (and perform checks).

(self, defn: OverloadedFuncDef)

Source from the content-addressed store, hash-verified

1528 )
1529
1530 def process_final_in_overload(self, defn: OverloadedFuncDef) -> None:
1531 """Detect the @final status of an overloaded function (and perform checks)."""
1532 # If the implementation is marked as @final (or the first overload in
1533 # stubs), then the whole overloaded definition if @final.
1534 if any(item.is_final for item in defn.items):
1535 # We anyway mark it as final because it was probably the intention.
1536 defn.is_final = True
1537 # Only show the error once per overload
1538 bad_final = next(ov for ov in defn.items if ov.is_final)
1539 if not self.is_stub_file:
1540 self.fail("@final should be applied only to overload implementation", bad_final)
1541 elif any(item.is_final for item in defn.items[1:]):
1542 bad_final = next(ov for ov in defn.items[1:] if ov.is_final)
1543 self.fail(
1544 "In a stub file @final must be applied only to the first overload", bad_final
1545 )
1546 if defn.impl is not None and defn.impl.is_final:
1547 defn.is_final = True
1548
1549 def process_static_or_class_method_in_overload(self, defn: OverloadedFuncDef) -> None:
1550 class_status = []

Callers 1

Calls 3

failMethod · 0.95
anyFunction · 0.85
nextFunction · 0.85

Tested by

no test coverage detected