A synthetic type representing some arbitrary expression that does not cleanly translate into a type. This synthetic type is only used at the beginning stages of semantic analysis and should be completely removing during the process for mapping UnboundTypes to actual types: we either
| 3104 | |
| 3105 | |
| 3106 | class RawExpressionType(ProperType): |
| 3107 | """A synthetic type representing some arbitrary expression that does not cleanly |
| 3108 | translate into a type. |
| 3109 | |
| 3110 | This synthetic type is only used at the beginning stages of semantic analysis |
| 3111 | and should be completely removing during the process for mapping UnboundTypes to |
| 3112 | actual types: we either turn it into a LiteralType or an AnyType. |
| 3113 | |
| 3114 | For example, suppose `Foo[1]` is initially represented as the following: |
| 3115 | |
| 3116 | UnboundType( |
| 3117 | name='Foo', |
| 3118 | args=[ |
| 3119 | RawExpressionType(value=1, base_type_name='builtins.int'), |
| 3120 | ], |
| 3121 | ) |
| 3122 | |
| 3123 | As we perform semantic analysis, this type will transform into one of two |
| 3124 | possible forms. |
| 3125 | |
| 3126 | If 'Foo' was an alias for 'Literal' all along, this type is transformed into: |
| 3127 | |
| 3128 | LiteralType(value=1, fallback=int_instance_here) |
| 3129 | |
| 3130 | Alternatively, if 'Foo' is an unrelated class, we report an error and instead |
| 3131 | produce something like this: |
| 3132 | |
| 3133 | Instance(type=typeinfo_for_foo, args=[AnyType(TypeOfAny.from_error)) |
| 3134 | |
| 3135 | If the "note" field is not None, the provided note will be reported alongside the |
| 3136 | error at this point. |
| 3137 | |
| 3138 | Note: if "literal_value" is None, that means this object is representing some |
| 3139 | expression that cannot possibly be a parameter of Literal[...]. For example, |
| 3140 | "Foo[3j]" would be represented as: |
| 3141 | |
| 3142 | UnboundType( |
| 3143 | name='Foo', |
| 3144 | args=[ |
| 3145 | RawExpressionType(value=None, base_type_name='builtins.complex'), |
| 3146 | ], |
| 3147 | ) |
| 3148 | """ |
| 3149 | |
| 3150 | __slots__ = ("literal_value", "base_type_name", "note") |
| 3151 | |
| 3152 | def __init__( |
| 3153 | self, |
| 3154 | literal_value: LiteralValue | None, |
| 3155 | base_type_name: str, |
| 3156 | line: int = -1, |
| 3157 | column: int = -1, |
| 3158 | note: str | None = None, |
| 3159 | ) -> None: |
| 3160 | super().__init__(line, column) |
| 3161 | self.literal_value = literal_value |
| 3162 | self.base_type_name = base_type_name |
| 3163 | self.note = note |
no outgoing calls
no test coverage detected
searching dependent graphs…