-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove TypeType exception for abstract instantiation #18094
base: master
Are you sure you want to change the base?
Conversation
If A is abstract, it's weird to me that we have a difference in the following two calls: ``` from abc import abstractmethod, ABCMeta class A(metaclass=ABCMeta): @AbstractMethod def __init__(self, a: int) -> None: pass def test_a(A_t: type[A]) -> None: A_t(1) A(1) ``` Mypy tries to then enforce soundness by preventing you from passing `A` to a parameter of `type[A]`. But this is very unpopular, since there are legitimate uses of `A` that have nothing to do with instantiation. See python#4717 As mentioned in https://discuss.python.org/t/compatibility-of-protocol-class-object-with-type-t-and-type-any/48442/2 I think we should switch to disallowing instantiation of `type[Proto]` and `type[Abstract]`. This also makes tackling `__init__` unsoundness more tractable. If people want unsound `__init__`, they can use `Callable[..., P]`.
This comment has been minimized.
This comment has been minimized.
4cf20ff
to
d72df74
Compare
Diff from mypy_primer, showing the effect of this PR on open source code: check-jsonschema (https://github.com/python-jsonschema/check-jsonschema)
+ src/check_jsonschema/cli/main_command.py:322: error: Cannot instantiate abstract class "Reporter" with abstract attributes "report_errors" and "report_success" [abstract]
cwltool (https://github.com/common-workflow-language/cwltool)
+ cwltool/command_line_tool.py: note: In member "job" of class "CommandLineTool":
+ cwltool/command_line_tool.py:955:13: error: Cannot instantiate abstract class "JobBase" with abstract attributes "_required_env" and "run" [abstract]
pydantic (https://github.com/pydantic/pydantic)
+ pydantic/_internal/_validators.py:57: error: Cannot instantiate abstract class "Sequence" with abstract attributes "__getitem__" and "__len__" [abstract]
+ pydantic/_internal/_validators.py:57: note: Error code "abstract" not covered by "type: ignore" comment
psycopg (https://github.com/psycopg/psycopg)
+ psycopg/psycopg/pq/pq_ctypes.py:346: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ psycopg/psycopg/pq/pq_ctypes.py:389: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ psycopg/psycopg/pq/pq_ctypes.py:396: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ psycopg/psycopg/pq/pq_ctypes.py:410: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ psycopg/psycopg/pq/pq_ctypes.py:420: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ psycopg/psycopg/pq/pq_ctypes.py:450: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ psycopg/psycopg/pq/pq_ctypes.py:474: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ psycopg/psycopg/pq/pq_ctypes.py:481: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ psycopg/psycopg/pq/pq_ctypes.py:494: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ psycopg/psycopg/_py_transformer.py:254: error: Cannot instantiate protocol class "Dumper" [misc]
+ psycopg/psycopg/_py_transformer.py:296: error: Cannot instantiate protocol class "Dumper" [misc]
+ psycopg/psycopg/_py_transformer.py:360: error: Cannot instantiate protocol class "Loader" [misc]
+ psycopg/psycopg/sql.py:378: error: Cannot instantiate protocol class "Escaping" [misc]
+ psycopg/psycopg/adapt.py:64: error: Cannot instantiate protocol class "Escaping" [misc]
+ psycopg/psycopg/adapt.py:74: error: Cannot instantiate protocol class "Escaping" [misc]
+ psycopg/psycopg/_copy_base.py:99: error: Cannot instantiate protocol class "Transformer" [misc]
+ psycopg/psycopg/types/string.py:135: error: Cannot instantiate protocol class "Escaping" [misc]
+ psycopg/psycopg/types/string.py:182: error: Cannot instantiate protocol class "Escaping" [misc]
+ psycopg/psycopg/_cursor_base.py:375: error: Cannot instantiate protocol class "Transformer" [misc]
+ psycopg/psycopg/client_cursor.py:44: error: Cannot instantiate protocol class "Transformer" [misc]
+ psycopg/psycopg/types/range.py:326: error: Cannot instantiate abstract class "BaseRangeDumper" with abstract attribute "dump" [abstract]
+ psycopg/psycopg/types/composite.py:141: error: Cannot instantiate protocol class "Transformer" [misc]
+ psycopg/psycopg/types/composite.py:165: error: Cannot instantiate protocol class "Transformer" [misc]
+ psycopg/psycopg/types/composite.py:239: error: Cannot instantiate protocol class "Transformer" [misc]
+ psycopg/psycopg/types/array.py:49: error: Cannot instantiate protocol class "Dumper" [misc]
+ psycopg/psycopg/types/multirange.py:222: error: Cannot instantiate abstract class "BaseMultirangeDumper" with abstract attribute "dump" [abstract]
+ tests/test_query.py:92: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/test_query.py:121: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/test_query.py:140: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/test_query.py:160: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/fix_faker.py:88: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/adapters_example.py:28: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/types/test_none.py:6: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/types/test_bool.py:29: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/types/test_bool.py:40: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/test_adapt.py:29: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/test_adapt.py:49: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/test_adapt.py:63: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/test_adapt.py:194: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/test_adapt.py:309: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/test_adapt.py:335: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/test_adapt.py:343: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/types/test_array.py:126: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/types/test_array.py:197: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/crdb/test_adapt.py:34: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/test_sql.py:57: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/test_sql.py:59: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/test_sql.py:63: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/test_sql.py:65: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/test_cursor_common_async.py:191: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/test_cursor_common.py:193: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/types/test_numeric.py:129: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/types/test_numeric.py:218: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/types/test_numeric.py:378: error: Cannot instantiate protocol class "Transformer" [misc]
+ tests/pq/test_escaping.py:19: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:28: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:38: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:42: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:58: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:67: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:77: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:81: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:97: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:104: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:126: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:135: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:145: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:153: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:164: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:172: error: Cannot instantiate protocol class "Escaping" [misc]
+ tests/pq/test_escaping.py:182: error: Cannot instantiate protocol class "Escaping" [misc]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/flows.py:278: error: Cannot instantiate abstract class "TaskRunner" with abstract attributes "duplicate" and "submit" [abstract]
+ src/prefect/cli/worker.py:157: error: Cannot instantiate abstract class "BaseWorker" with abstract attribute "run" [abstract]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/io/json/_json.py:192: error: Cannot instantiate abstract class "Writer" with abstract attribute "obj_to_write" [abstract]
+ pandas/core/apply.py:103: error: Cannot instantiate abstract class "FrameApply" with abstract attributes "apply_with_numba", "generate_numba_apply_func", ... and "wrap_results_for_axis" (3 methods suppressed) [abstract]
+ pandas/core/indexes/datetimelike.py:187: error: Cannot instantiate abstract class "DatetimeIndexOpsMixin" with abstract attribute "_resolution_obj" [abstract]
+ pandas/core/computation/eval.py:390: error: Cannot instantiate abstract class "AbstractEngine" with abstract attribute "_evaluate" [abstract]
+ pandas/plotting/_matplotlib/__init__.py:70: error: Cannot instantiate abstract class "MPLPlot" with abstract attributes "_kind" and "_post_plot_logic" [abstract]
bidict (https://github.com/jab/bidict)
+ bidict/_base.py: note: In member "__init__" of class "BidictBase":
+ bidict/_base.py:159:22: error: Cannot instantiate abstract class "MutableMapping" with abstract attributes "__delitem__", "__getitem__", "__iter__", "__len__" and "__setitem__" [abstract]
+ bidict/_base.py:160:22: error: Cannot instantiate abstract class "MutableMapping" with abstract attributes "__delitem__", "__getitem__", "__iter__", "__len__" and "__setitem__" [abstract]
pylint (https://github.com/pycqa/pylint)
+ pylint/pyreverse/writer.py:160: error: Cannot instantiate abstract class "Printer" with abstract attributes "_close_graph", "_open_graph", "emit_edge" and "emit_node" [abstract]
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/connectionpool.py:250: error: Cannot instantiate protocol class "BaseHTTPConnection" [misc]
+ src/urllib3/connectionpool.py:1069: error: Cannot instantiate protocol class "BaseHTTPSConnection" [misc]
dd-trace-py (https://github.com/DataDog/dd-trace-py)
+ ddtrace/internal/telemetry/metrics_namespaces.py:54: error: Cannot instantiate abstract class "Metric" with abstract attribute "add_point" [abstract]
+ ddtrace/appsec/_iast/_taint_tracking/__init__.py:307: error: Cannot instantiate abstract class "Sequence" with abstract attributes "__getitem__" and "__len__" [abstract]
+ ddtrace/appsec/_iast/_taint_tracking/__init__.py:307: note: Error code "abstract" not covered by "type: ignore" comment
artigraph (https://github.com/artigraph/artigraph)
+ src/arti/storage/__init__.py:217: error: Cannot instantiate abstract class "StoragePartition" with abstract attribute "compute_content_fingerprint" [abstract]
sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/config.py: note: In function "evaluate_copyright_placeholders":
+ sphinx/config.py:630:33: error: Cannot instantiate abstract class "Sequence" with abstract attributes "__getitem__" and "__len__" [abstract]
+ sphinx/config.py:630:33: note: Error code "abstract" not covered by "type: ignore" comment
+ sphinx/config.py: note: In function "correct_copyright_year":
+ sphinx/config.py:661:29: error: Cannot instantiate abstract class "Sequence" with abstract attributes "__getitem__" and "__len__" [abstract]
+ sphinx/config.py:661:29: note: Error code "abstract" not covered by "type: ignore" comment
+ sphinx/writers/latex.py: note: In member "generate_indices" of class "LaTeXTranslator":
+ sphinx/writers/latex.py:572:42: error: Cannot instantiate abstract class "Index" with abstract attribute "generate" [abstract]
+ sphinx/builders/html/__init__.py: note: In member "prepare_writing" of class "StandaloneHTMLBuilder":
+ sphinx/builders/html/__init__.py:472:41: error: Cannot instantiate abstract class "Index" with abstract attribute "generate" [abstract]
+ sphinx/writers/texinfo.py: note: In member "collect_indices" of class "TexinfoTranslator":
+ sphinx/writers/texinfo.py:500:42: error: Cannot instantiate abstract class "Index" with abstract attribute "generate" [abstract]
bokeh (https://github.com/bokeh/bokeh)
+ src/bokeh/command/bootstrap.py: note: In function "main":
+ src/bokeh/command/bootstrap.py:106:22: error: Cannot instantiate abstract class "Subcommand" with abstract attribute "invoke" [abstract]
koda-validate (https://github.com/keithasaurus/koda-validate)
+ koda_validate/dataclasses.py:214: error: Cannot instantiate protocol class "DataclassLike" [misc]
+ koda_validate/dataclasses.py:266: error: Cannot instantiate protocol class "DataclassLike" [misc]
streamlit (https://github.com/streamlit/streamlit)
+ lib/streamlit/runtime/runtime.py: note: In member "__init__" of class "Runtime":
+ lib/streamlit/runtime/runtime.py:210:29: error: Cannot instantiate protocol class "SessionManager" [misc]
+ lib/streamlit/runtime/connection_factory.py: note: In function "_create_connection":
+ lib/streamlit/runtime/connection_factory.py:81:16: error: Cannot instantiate abstract class "BaseConnection" with abstract attribute "_connect" [abstract]
pip (https://github.com/pypa/pip)
+ src/pip/_internal/metadata/importlib/_dists.py:77: error: Cannot instantiate abstract class "WheelDistribution" with abstract attribute "locate_file" [abstract]
xarray (https://github.com/pydata/xarray)
+ xarray/namedarray/dtypes.py: note: In function "maybe_promote":
+ xarray/namedarray/dtypes.py:86: error: Cannot instantiate abstract class "generic" with abstract attribute "__init__" [abstract]
spark (https://github.com/apache/spark)
+ python/pyspark/pandas/indexing.py:446: error: Cannot instantiate abstract class "LocIndexerLike" with abstract attributes "_select_cols_by_iterable", "_select_cols_by_series", ... and "_select_rows_else" (7 methods suppressed) [abstract]
+ python/pyspark/pandas/indexing.py:473: error: Cannot instantiate abstract class "LocIndexerLike" with abstract attributes "_select_cols_by_iterable", "_select_cols_by_series", ... and "_select_rows_else" (7 methods suppressed) [abstract]
+ python/pyspark/pandas/indexing.py:614: error: Cannot instantiate abstract class "LocIndexerLike" with abstract attributes "_select_cols_by_iterable", "_select_cols_by_series", ... and "_select_rows_else" (7 methods suppressed) [abstract]
+ python/pyspark/pandas/indexing.py:704: error: Cannot instantiate abstract class "LocIndexerLike" with abstract attributes "_select_cols_by_iterable", "_select_cols_by_series", ... and "_select_rows_else" (7 methods suppressed) [abstract]
colour (https://github.com/colour-science/colour)
+ colour/io/luts/lut.py:2248: error: Cannot instantiate abstract class "AbstractLUT" with abstract attributes "_validate_domain", "_validate_table", ... and "linear_table" (3 methods suppressed) [abstract]
+ colour/continuous/signal.py:533: error: Cannot instantiate protocol class "ProtocolExtrapolator" [misc]
+ colour/continuous/signal.py:534: error: Cannot instantiate protocol class "ProtocolInterpolator" [misc]
+ colour/colorimetry/spectrum.py:1208: error: Cannot instantiate protocol class "ProtocolInterpolator" [misc]
beartype (https://github.com/beartype/beartype)
+ beartype/_util/kind/map/utilmapset.py:144: error: Cannot instantiate abstract class "Mapping" with abstract attributes "__getitem__", "__iter__" and "__len__" [abstract]
+ beartype/_util/kind/map/utilmapset.py:144: note: Error code "abstract" not covered by "type: ignore" comment
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/python.py:311: error: Cannot instantiate protocol class "Iterable" [misc]
+ scrapy/utils/python.py:311: note: Error code "misc" not covered by "type: ignore" comment
+ scrapy/utils/reactor.py:117: error: Cannot instantiate abstract class "AbstractEventLoop" with abstract attributes "add_reader", "add_signal_handler", ... and "time" (48 methods suppressed) [abstract]
+ scrapy/core/scheduler.py:74: error: Cannot instantiate abstract class "BaseScheduler" with abstract attributes "enqueue_request", "has_pending_requests" and "next_request" [abstract]
+ scrapy/pipelines/media.py:118: error: Cannot instantiate abstract class "MediaPipeline" with abstract attributes "file_path", "get_media_requests", "media_downloaded", "media_failed" and "media_to_download" [abstract]
+ scrapy/pipelines/files.py:506: error: Cannot instantiate protocol class "FilesStoreProtocol" [misc]
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ bson/__init__.py:626: error: Cannot instantiate abstract class "Mapping" with abstract attributes "__getitem__", "__iter__" and "__len__" [abstract]
+ bson/__init__.py:626: note: Error code "abstract" not covered by "type: ignore" comment
+ bson/__init__.py:1185: error: Cannot instantiate abstract class "Mapping" with abstract attributes "__getitem__", "__iter__" and "__len__" [abstract]
+ bson/json_util.py:527: error: Cannot instantiate abstract class "MutableMapping" with abstract attributes "__delitem__", "__getitem__", "__iter__", "__len__" and "__setitem__" [abstract]
+ bson/json_util.py:527: note: Error code "abstract" not covered by "type: ignore" comment
pyjwt (https://github.com/jpadilla/pyjwt)
+ jwt/algorithms.py:160: error: Cannot instantiate abstract class "HashAlgorithm" with abstract attributes "block_size", "digest_size" and "name" [abstract]
+ jwt/algorithms.py:477: error: Cannot instantiate abstract class "HashAlgorithm" with abstract attributes "block_size", "digest_size" and "name" [abstract]
+ jwt/algorithms.py:481: error: Cannot instantiate abstract class "HashAlgorithm" with abstract attributes "block_size", "digest_size" and "name" [abstract]
+ jwt/algorithms.py:530: error: Cannot instantiate abstract class "HashAlgorithm" with abstract attributes "block_size", "digest_size" and "name" [abstract]
+ jwt/algorithms.py:546: error: Cannot instantiate abstract class "HashAlgorithm" with abstract attributes "block_size", "digest_size" and "name" [abstract]
+ jwt/algorithms.py:690: error: Cannot instantiate abstract class "HashAlgorithm" with abstract attributes "block_size", "digest_size" and "name" [abstract]
+ jwt/algorithms.py:691: error: Cannot instantiate abstract class "HashAlgorithm" with abstract attributes "block_size", "digest_size" and "name" [abstract]
+ jwt/algorithms.py:693: error: Cannot instantiate abstract class "HashAlgorithm" with abstract attributes "block_size", "digest_size" and "name" [abstract]
+ jwt/algorithms.py:702: error: Cannot instantiate abstract class "HashAlgorithm" with abstract attributes "block_size", "digest_size" and "name" [abstract]
+ jwt/algorithms.py:703: error: Cannot instantiate abstract class "HashAlgorithm" with abstract attributes "block_size", "digest_size" and "name" [abstract]
+ jwt/algorithms.py:705: error: Cannot instantiate abstract class "HashAlgorithm" with abstract attributes "block_size", "digest_size" and "name" [abstract]
paasta (https://github.com/yelp/paasta)
+ paasta_tools/metrics/metrics_lib.py:90: error: Cannot instantiate abstract class "BaseMetrics" with abstract attributes "create_counter", "create_gauge", "create_timer" and "emit_event" [abstract]
rich (https://github.com/Textualize/rich)
+ rich/logging.py:93: error: Cannot instantiate abstract class "Highlighter" with abstract attribute "highlight" [abstract]
+ rich/layout.py:172: error: Cannot instantiate abstract class "Splitter" with abstract attributes "divide" and "get_tree_icon" [abstract]
+ rich/layout.py:280: error: Cannot instantiate abstract class "Splitter" with abstract attributes "divide" and "get_tree_icon" [abstract]
pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/capture.py:918: error: Cannot instantiate abstract class "CaptureBase" with abstract attributes "__init__", "done", ... and "writeorg" (4 methods suppressed) [abstract]
+ src/_pytest/capture.py:919: error: Cannot instantiate abstract class "CaptureBase" with abstract attributes "__init__", "done", ... and "writeorg" (4 methods suppressed) [abstract]
comtypes (https://github.com/enthought/comtypes)
+ comtypes/typeinfo.py:370: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ comtypes/typeinfo.py:377: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ comtypes/typeinfo.py:378: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ comtypes/typeinfo.py:462: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ comtypes/typeinfo.py:475: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ comtypes/automation.py:826: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ comtypes/automation.py:827: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ comtypes/automation.py:837: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ comtypes/automation.py:854: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ comtypes/stream.py:46: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
isort (https://github.com/pycqa/isort)
+ isort/deprecated/finders.py:368: error: Cannot instantiate abstract class "BaseFinder" with abstract attribute "find" [abstract]
hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+ tests/annotations/mypy_checks.py:26: error: Cannot instantiate protocol class "BuildsWithSig" [misc]
+ tests/annotations/mypy_checks.py:26: note: Error code "misc" not covered by "type: ignore" comment
+ tests/annotations/mypy_checks.py:50: error: Cannot instantiate protocol class "BuildsWithSig" [misc]
+ tests/annotations/mypy_checks.py:50: note: Error code "misc" not covered by "type: ignore" comment
CPython (peg_generator) (https://github.com/python/cpython)
+ Tools/peg_generator/pegen/parser.py:326: error: Cannot instantiate abstract class "Parser" with abstract attribute "start" [abstract]
+ Tools/peg_generator/pegen/testutil.py:41: error: Cannot instantiate abstract class "Parser" with abstract attribute "start" [abstract]
freqtrade (https://github.com/freqtrade/freqtrade)
+ freqtrade/rpc/api_server/ws/channel.py:55: error: Cannot instantiate abstract class "WebSocketSerializer" with abstract attributes "_deserialize" and "_serialize" [abstract]
+ freqtrade/data/history/datahandlers/idatahandler.py:579: error: Cannot instantiate abstract class "IDataHandler" with abstract attributes "_ohlcv_load", "_trades_load", ... and "trades_append" (3 methods suppressed) [abstract]
steam.py (https://github.com/Gobot1234/steam.py)
+ steam/profile.py:145: error: Cannot instantiate protocol class "SupportsEquip" [misc]
+ steam/chat.py:552: error: Cannot instantiate abstract class "ChatGroup" with abstract attributes "_get_partial_member" and "chunk" [abstract]
+ steam/_gc/state.py:177: error: Cannot instantiate abstract class "Inventory" with abstract attribute "__getitem__" [abstract]
+ steam/ext/commands/commands.py:520: error: Cannot instantiate protocol class "ConverterBase" [misc]
+ steam/ext/commands/commands.py:566: error: Cannot instantiate protocol class "ConverterBase" [misc]
discord.py (https://github.com/Rapptz/discord.py)
+ discord/opus.py:411: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ discord/opus.py:501: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ discord/gateway.py:328: error: Cannot instantiate protocol class "_DecompressionContext" [misc]
+ discord/ext/commands/converter.py:1151: error: Cannot instantiate protocol class "Converter" [misc]
+ discord/ext/commands/converter.py:1326: error: Cannot instantiate protocol class "Converter" [misc]
+ discord/ext/commands/hybrid.py:143: error: Cannot instantiate protocol class "Converter" [misc]
aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/payload.py:116:24: error: Cannot instantiate abstract class "Payload" with abstract attributes "decode" and "write" [abstract]
+ aiohttp/payload.py:116:24: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-abstract for more info
+ aiohttp/web_protocol.py:256:21: error: Cannot instantiate abstract class "AbstractAsyncAccessLogger" with abstract attribute "log" [abstract]
+ aiohttp/web_protocol.py:259:33: error: Cannot instantiate abstract class "AbstractAccessLogger" with abstract attribute "log" [abstract]
ibis (https://github.com/ibis-project/ibis)
+ ibis/common/collections.py:242: error: Cannot instantiate abstract class "MapSet" with abstract attributes "__getitem__", "__iter__" and "__len__" [abstract]
+ ibis/common/collections.py:249: error: Cannot instantiate abstract class "MapSet" with abstract attributes "__getitem__", "__iter__" and "__len__" [abstract]
+ ibis/common/collections.py:256: error: Cannot instantiate abstract class "MapSet" with abstract attributes "__getitem__", "__iter__" and "__len__" [abstract]
+ ibis/common/collections.py:263: error: Cannot instantiate abstract class "MapSet" with abstract attributes "__getitem__", "__iter__" and "__len__" [abstract]
+ ibis/common/collections.py:272: error: Cannot instantiate abstract class "MapSet" with abstract attributes "__getitem__", "__iter__" and "__len__" [abstract]
+ ibis/common/graph.py:254: error: Cannot instantiate abstract class "Node" with abstract attributes "__argnames__", "__args__" and "__hash__" [abstract]
+ ibis/expr/datatypes/core.py:188: error: Cannot instantiate abstract class "DataType" with abstract attributes "column" and "scalar" [abstract]
+ ibis/backends/__init__.py:902: error: Cannot instantiate abstract class "BaseBackend" with abstract attributes "create_table", "create_view", ... and "version" (6 methods suppressed) [abstract]
+ ibis/expr/types/core.py:775: error: Cannot instantiate abstract class "Binary" with abstract attribute "dtype" [abstract]
+ ibis/backends/tests/base.py:168: error: Cannot instantiate abstract class "BackendTest" with abstract attributes "connect" and "deps" [abstract]
core (https://github.com/home-assistant/core)
+ homeassistant/components/recorder/migration.py:937: error: Cannot instantiate abstract class "_SchemaVersionMigrator" with abstract attribute "_apply_update" [abstract]
+ homeassistant/components/google_assistant/helpers.py:547: error: Cannot instantiate abstract class "_Trait" with abstract attribute "supported" [abstract]
+ homeassistant/components/integration/sensor.py:112: error: Cannot instantiate abstract class "_IntegrationMethod" with abstract attributes "calculate_area_with_two_states" and "validate_states" [abstract]
+ homeassistant/components/broadlink/updater.py:48: error: Cannot instantiate abstract class "BroadlinkUpdateManager" with abstract attribute "async_fetch_data" [abstract]
+ homeassistant/components/unifi/hub/entity_loader.py:174: error: Cannot instantiate abstract class "UnifiEntity" with abstract attribute "async_update_state" [abstract]
+ homeassistant/components/unifi/hub/entity_loader.py:199: error: Cannot instantiate abstract class "UnifiEntity" with abstract attribute "async_update_state" [abstract]
+ homeassistant/components/mqtt/entity.py:266: error: Cannot instantiate abstract class "MqttEntity" with abstract attributes "_prepare_subscribe_topics", "_subscribe_topics" and "config_schema" [abstract]
+ homeassistant/components/mqtt/entity.py:305: error: Cannot instantiate abstract class "MqttEntity" with abstract attributes "_prepare_subscribe_topics", "_subscribe_topics" and "config_schema" [abstract]
+ homeassistant/components/tplink/entity.py:362: error: Cannot instantiate abstract class "CoordinatedTPLinkFeatureEntity" with abstract attribute "_async_update_attrs" [abstract]
+ homeassistant/components/axis/hub/entity_loader.py:74: error: Cannot instantiate abstract class "AxisEventEntity" with abstract attribute "async_event_callback" [abstract]
pegen (https://github.com/we-like-parsers/pegen)
+ src/pegen/parser.py:334: error: Cannot instantiate abstract class "Parser" with abstract attribute "start" [abstract]
+ src/pegen/utils.py:52: error: Cannot instantiate abstract class "Parser" with abstract attribute "start" [abstract]
python-chess (https://github.com/niklasf/python-chess)
+ chess/gaviota.py:1931: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ chess/gaviota.py:1992: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ chess/gaviota.py:1993: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ chess/gaviota.py:2003: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
+ chess/gaviota.py:2004: error: Cannot instantiate abstract class "Array" with abstract attributes "_length_" and "_type_" [abstract]
ignite (https://github.com/pytorch/ignite)
+ ignite/handlers/param_scheduler.py:258: error: Cannot instantiate abstract class "ParamScheduler" with abstract attribute "get_param" [abstract]
+ ignite/handlers/state_param_scheduler.py:109: error: Cannot instantiate abstract class "StateParamScheduler" with abstract attribute "get_param" [abstract]
... (truncated 62 lines) ...``` |
I think it would be good to relax this, but the mypy_primer fallout is quite significant. I looked at def __or__(self, other: collections.abc.Mapping) -> Self:
...
return self.__class__(union) I wonder if there are some other patterns in the mypy_primer output that look like straightforward false positives (and we might be able to support). |
If A is abstract, it's weird to me that we have a difference in the following two calls:
Mypy tries to then enforce soundness by preventing you from passing
A
to a parameter oftype[A]
. But this is very unpopular, since there are legitimate uses ofA
that have nothing to do with instantiation. See #4717As mentioned in
https://discuss.python.org/t/compatibility-of-protocol-class-object-with-type-t-and-type-any/48442/2 I think we should switch to disallowing instantiation of
type[Proto]
andtype[Abstract]
.This also makes tackling
__init__
unsoundness more tractable. If people want unsound__init__
, they can useCallable[..., P]
.