Special typing construct to indicate final names to type checkers. A final name cannot be re-assigned or overridden in a subclass. For example:: MAX_SIZE: Final = 9000 MAX_SIZE += 1 # Error reported by type checker class Connection: TIMEOUT: Final[int
(self, parameters)
| 720 | |
| 721 | @_SpecialForm |
| 722 | def Final(self, parameters): |
| 723 | """Special typing construct to indicate final names to type checkers. |
| 724 | |
| 725 | A final name cannot be re-assigned or overridden in a subclass. |
| 726 | |
| 727 | For example:: |
| 728 | |
| 729 | MAX_SIZE: Final = 9000 |
| 730 | MAX_SIZE += 1 # Error reported by type checker |
| 731 | |
| 732 | class Connection: |
| 733 | TIMEOUT: Final[int] = 10 |
| 734 | |
| 735 | class FastConnector(Connection): |
| 736 | TIMEOUT = 1 # Error reported by type checker |
| 737 | |
| 738 | There is no runtime checking of these properties. |
| 739 | """ |
| 740 | item = _type_check(parameters, f'{self} accepts only single type.', allow_special_forms=True) |
| 741 | return _GenericAlias(self, (item,)) |
| 742 | |
| 743 | @_SpecialForm |
| 744 | def Optional(self, parameters): |
nothing calls this directly
no test coverage detected