|
47 | 47 | Var, |
48 | 48 | check_arg_kinds, |
49 | 49 | check_arg_names, |
50 | | - get_nongen_builtins, |
51 | 50 | ) |
52 | 51 | from mypy.options import INLINE_TYPEDDICT, Options |
53 | 52 | from mypy.plugin import AnalyzeTypeContext, Plugin, TypeAnalyzerPluginInterface |
|
136 | 135 | "mypy_extensions.KwArg": ARG_STAR2, |
137 | 136 | } |
138 | 137 |
|
139 | | -GENERIC_STUB_NOT_AT_RUNTIME_TYPES: Final = { |
140 | | - "queue.Queue", |
141 | | - "builtins._PathLike", |
142 | | - "asyncio.futures.Future", |
143 | | -} |
144 | | - |
145 | 138 | SELF_TYPE_NAMES: Final = {"typing.Self", "typing_extensions.Self"} |
146 | 139 |
|
147 | 140 |
|
@@ -186,17 +179,6 @@ def analyze_type_alias( |
186 | 179 | return res, analyzer.aliases_used |
187 | 180 |
|
188 | 181 |
|
189 | | -def no_subscript_builtin_alias(name: str, propose_alt: bool = True) -> str: |
190 | | - class_name = name.split(".")[-1] |
191 | | - msg = f'"{class_name}" is not subscriptable' |
192 | | - # This should never be called if the python_version is 3.9 or newer |
193 | | - nongen_builtins = get_nongen_builtins((3, 8)) |
194 | | - replacement = nongen_builtins[name] |
195 | | - if replacement and propose_alt: |
196 | | - msg += f', use "{replacement}" instead' |
197 | | - return msg |
198 | | - |
199 | | - |
200 | 182 | class TypeAnalyser(SyntheticTypeVisitor[Type], TypeAnalyzerPluginInterface): |
201 | 183 | """Semantic analyzer for types. |
202 | 184 |
|
@@ -360,14 +342,6 @@ def visit_unbound_type_nonoptional(self, t: UnboundType, defining_literal: bool) |
360 | 342 | hook = self.plugin.get_type_analyze_hook(fullname) |
361 | 343 | if hook is not None: |
362 | 344 | return hook(AnalyzeTypeContext(t, t, self)) |
363 | | - if ( |
364 | | - fullname in get_nongen_builtins(self.options.python_version) |
365 | | - and t.args |
366 | | - and not self.always_allow_new_syntax |
367 | | - ): |
368 | | - self.fail( |
369 | | - no_subscript_builtin_alias(fullname, propose_alt=not self.defining_alias), t |
370 | | - ) |
371 | 345 | tvar_def = self.tvar_scope.get_binding(sym) |
372 | 346 | if isinstance(sym.node, ParamSpecExpr): |
373 | 347 | if tvar_def is None: |
@@ -2033,44 +2007,14 @@ def get_omitted_any( |
2033 | 2007 | unexpanded_type: Type | None = None, |
2034 | 2008 | ) -> AnyType: |
2035 | 2009 | if disallow_any: |
2036 | | - nongen_builtins = get_nongen_builtins(options.python_version) |
2037 | | - if fullname in nongen_builtins: |
2038 | | - typ = orig_type |
2039 | | - # We use a dedicated error message for builtin generics (as the most common case). |
2040 | | - alternative = nongen_builtins[fullname] |
2041 | | - fail( |
2042 | | - message_registry.IMPLICIT_GENERIC_ANY_BUILTIN.format(alternative), |
2043 | | - typ, |
2044 | | - code=codes.TYPE_ARG, |
2045 | | - ) |
2046 | | - else: |
2047 | | - typ = unexpanded_type or orig_type |
2048 | | - type_str = typ.name if isinstance(typ, UnboundType) else format_type_bare(typ, options) |
| 2010 | + typ = unexpanded_type or orig_type |
| 2011 | + type_str = typ.name if isinstance(typ, UnboundType) else format_type_bare(typ, options) |
2049 | 2012 |
|
2050 | | - fail( |
2051 | | - message_registry.BARE_GENERIC.format(quote_type_string(type_str)), |
2052 | | - typ, |
2053 | | - code=codes.TYPE_ARG, |
2054 | | - ) |
2055 | | - base_type = get_proper_type(orig_type) |
2056 | | - base_fullname = ( |
2057 | | - base_type.type.fullname if isinstance(base_type, Instance) else fullname |
2058 | | - ) |
2059 | | - # Ideally, we'd check whether the type is quoted or `from __future__ annotations` |
2060 | | - # is set before issuing this note |
2061 | | - if ( |
2062 | | - options.python_version < (3, 9) |
2063 | | - and base_fullname in GENERIC_STUB_NOT_AT_RUNTIME_TYPES |
2064 | | - ): |
2065 | | - # Recommend `from __future__ import annotations` or to put type in quotes |
2066 | | - # (string literal escaping) for classes not generic at runtime |
2067 | | - note( |
2068 | | - "Subscripting classes that are not generic at runtime may require " |
2069 | | - "escaping, see https://mypy.readthedocs.io/en/stable/runtime_troubles.html" |
2070 | | - "#not-generic-runtime", |
2071 | | - typ, |
2072 | | - code=codes.TYPE_ARG, |
2073 | | - ) |
| 2013 | + fail( |
| 2014 | + message_registry.BARE_GENERIC.format(quote_type_string(type_str)), |
| 2015 | + typ, |
| 2016 | + code=codes.TYPE_ARG, |
| 2017 | + ) |
2074 | 2018 |
|
2075 | 2019 | any_type = AnyType(TypeOfAny.from_error, line=typ.line, column=typ.column) |
2076 | 2020 | else: |
|
0 commit comments