Instance type that has not been bound during semantic analysis.
| 1028 | |
| 1029 | |
| 1030 | class UnboundType(ProperType): |
| 1031 | """Instance type that has not been bound during semantic analysis.""" |
| 1032 | |
| 1033 | __slots__ = ( |
| 1034 | "name", |
| 1035 | "args", |
| 1036 | "optional", |
| 1037 | "empty_tuple_index", |
| 1038 | "original_str_expr", |
| 1039 | "original_str_fallback", |
| 1040 | ) |
| 1041 | |
| 1042 | def __init__( |
| 1043 | self, |
| 1044 | name: str, |
| 1045 | args: Sequence[Type] | None = None, |
| 1046 | *, |
| 1047 | line: int = -1, |
| 1048 | column: int = -1, |
| 1049 | optional: bool = False, |
| 1050 | empty_tuple_index: bool = False, |
| 1051 | original_str_expr: str | None = None, |
| 1052 | original_str_fallback: str | None = None, |
| 1053 | ) -> None: |
| 1054 | super().__init__(line, column) |
| 1055 | if not args: |
| 1056 | args = [] |
| 1057 | self.name = name |
| 1058 | self.args = tuple(args) |
| 1059 | # Should this type be wrapped in an Optional? |
| 1060 | self.optional = optional |
| 1061 | # Special case for X[()] |
| 1062 | self.empty_tuple_index = empty_tuple_index |
| 1063 | # If this UnboundType was originally defined as a str or bytes, keep track of |
| 1064 | # the original contents of that string-like thing. This way, if this UnboundExpr |
| 1065 | # ever shows up inside of a LiteralType, we can determine whether that |
| 1066 | # Literal[...] is valid or not. E.g. Literal[foo] is most likely invalid |
| 1067 | # (unless 'foo' is an alias for another literal or something) and |
| 1068 | # Literal["foo"] most likely is. |
| 1069 | # |
| 1070 | # We keep track of the entire string instead of just using a boolean flag |
| 1071 | # so we can distinguish between things like Literal["foo"] vs |
| 1072 | # Literal[" foo "]. |
| 1073 | # |
| 1074 | # We also keep track of what the original base fallback type was supposed to be |
| 1075 | # so we don't have to try and recompute it later |
| 1076 | self.original_str_expr = original_str_expr |
| 1077 | self.original_str_fallback = original_str_fallback |
| 1078 | |
| 1079 | def copy_modified(self, args: Bogus[Sequence[Type] | None] = _dummy) -> UnboundType: |
| 1080 | if args is _dummy: |
| 1081 | args = self.args |
| 1082 | return UnboundType( |
| 1083 | name=self.name, |
| 1084 | args=args, |
| 1085 | line=self.line, |
| 1086 | column=self.column, |
| 1087 | optional=self.optional, |
no outgoing calls
searching dependent graphs…