Skip to content
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

Always infer union types for ternaries #12395

Closed
wants to merge 1 commit into from

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented Mar 21, 2022

Undoes #5095. Part of #12056. This fails a few tests but I want to
see the mypy-primer output before I spend time fixing them.

Undoes python#5095. Part of python#12056. This fails a few tests but I want to
see the mypy-primer output before I spend time fixing them.
@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

alectryon (https://github.com/cpitclaudel/alectryon)
+ alectryon/json.py:324: error: Need type annotation for "caches"
+ alectryon/docutils.py:359: error: Need type annotation for "beg"
+ alectryon/docutils.py:360: error: Need type annotation for "end"

pandera (https://github.com/pandera-dev/pandera)
+ pandera/checks.py:447: error: Item "bool" of "Union[Any, bool]" has no attribute "all"  [union-attr]
+ pandera/checks.py:449: error: Item "bool" of "Union[Any, bool]" has no attribute "all"  [union-attr]

ignite (https://github.com/pytorch/ignite)
+ ignite/distributed/comp_models/base.py:125: error: Need type annotation for "shape"  [var-annotated]
+ ignite/metrics/precision.py:37: error: Need type annotation for "init_value"  [var-annotated]
+ ignite/metrics/fbeta.py:154: error: Unused "type: ignore" comment
+ ignite/metrics/fbeta.py:163: error: Unused "type: ignore" comment
+ ignite/handlers/time_profilers.py:417: error: Incompatible types in string interpolation (expression has type "str", placeholder has type "Union[int, float]")  [str-format]

graphql-core (https://github.com/graphql-python/graphql-core)
+ src/graphql/language/visitor.py:248: error: No overload variant of "getattr" matches argument types "Any", "Node", "None"
+ src/graphql/language/visitor.py:248: note: Possible overload variants:
+ src/graphql/language/visitor.py:248: note:     def getattr(__o, object, str) -> Any
+ src/graphql/language/visitor.py:248: note:     def getattr(__o, object, str, None) -> Optional[Any]
+ src/graphql/language/visitor.py:248: note:     def getattr(__o, object, str, bool) -> Union[Any, bool]
+ src/graphql/language/visitor.py:248: note:     def getattr(__o, object, name: str, List[Any]) -> Union[Any, List[Any]]
+ src/graphql/language/visitor.py:248: note:     def getattr(__o, object, name: str, Dict[Any, Any]) -> Union[Any, Dict[Any, Any]]
+ src/graphql/language/visitor.py:248: note:     def [_T] getattr(__o, object, str, _T) -> Union[Any, _T]
+ src/graphql/language/visitor.py:295: error: Incompatible types in assignment (expression has type "Union[Any, Tuple[str, ...], Tuple[Node, ...]]", variable has type "Tuple[Node, ...]")
+ src/graphql/language/parser.py:383: error: Incompatible types in assignment (expression has type "Callable[[], ArgumentNode]", variable has type "Union[Callable[[], ConstArgumentNode], Callable[[bool], ArgumentNode]]")
+ src/graphql/utilities/build_client_schema.py:401: error: Need type annotation for "directives"
+ src/graphql/execution/subscribe.py:89: error: Incompatible return value type (got "Union[Any, Awaitable[ExecutionResult], ExecutionResult]", expected "ExecutionResult")
+ src/graphql/validation/rules/unique_field_definition_names.py:21: error: Need type annotation for "existing_type_map"
+ src/graphql/validation/rules/unique_enum_value_names.py:21: error: Need type annotation for "existing_type_map"
+ src/graphql/validation/rules/known_type_names.py:31: error: Need type annotation for "existing_types_map"
+ tests/execution/test_abstract.py:45: error: Unused "type: ignore" comment

starlette (https://github.com/encode/starlette)
+ starlette/datastructures.py:250: error: Need type annotation for "value"  [var-annotated]
+ starlette/datastructures.py:395: error: Need type annotation for "value"  [var-annotated]
+ starlette/background.py:33: error: Need type annotation for "tasks"  [var-annotated]

boostedblob (https://github.com/hauntsaninja/boostedblob)
+ boostedblob/read.py:39: error: Need type annotation for "range_header"
+ boostedblob/read.py:56: error: Need type annotation for "range_header"

pydantic (https://github.com/samuelcolvin/pydantic)
+ pydantic/utils.py:255: error: Need type annotation for "kwargs"  [var-annotated]

bidict (https://github.com/jab/bidict)
+ bidict/_base.py:539: error: Unused "type: ignore" comment

psycopg (https://github.com/psycopg/psycopg)
+ psycopg/psycopg/waiting.py:65: error: Incompatible types in assignment (expression has type "Optional[Any]", variable has type "RV")  [assignment]
+ psycopg/psycopg/waiting.py:97: error: Incompatible types in assignment (expression has type "Optional[Any]", variable has type "RV")  [assignment]
+ psycopg/psycopg/waiting.py:147: error: Incompatible types in assignment (expression has type "Optional[Any]", variable has type "RV")  [assignment]
+ psycopg/psycopg/waiting.py:203: error: Incompatible types in assignment (expression has type "Optional[Any]", variable has type "RV")  [assignment]
+ psycopg/psycopg/waiting.py:242: error: Incompatible types in assignment (expression has type "Optional[Any]", variable has type "RV")  [assignment]

paasta (https://github.com/yelp/paasta)
+ paasta_tools/cli/utils.py:487: error: Need type annotation for "autoscaling_arg"
+ paasta_tools/cli/utils.py:490: error: Need type annotation for "groupings_args"
+ paasta_tools/cli/utils.py:491: error: Need type annotation for "cache_arg"
+ paasta_tools/config_utils.py:54: error: Need type annotation for "content"

mypy (https://github.com/python/mypy)
+ mypy/checkexpr.py:3165: error: Need type annotation for "names_to_types"  [var-annotated]
+ mypy/build.py:2833: error: Need type annotation for "new"  [var-annotated]
+ mypy/dmypy_server.py:282: error: Need type annotation for "data"  [var-annotated]
+ mypy/test/testcheck.py:137: error: Need type annotation for "ops"  [var-annotated]

mypy_primer (https://github.com/hauntsaninja/mypy_primer)
- mypy_primer.py:557: error: Argument 1 to "iter" has incompatible type "List[Project]"; expected "_SupportsIter[Generator[Project, None, None]]"
+ mypy_primer.py:557: error: Argument 1 to "iter" has incompatible type "List[Any]"; expected "_SupportsIter[Generator[Any, None, None]]"

rotki (https://github.com/rotki/rotki)
+ rotkehlchen/errors.py:48: error: Need type annotation for "message_payload"
+ rotkehlchen/chain/ethereum/modules/makerdao/vaults.py:232: error: Need type annotation for "starting_assets"
+ rotkehlchen/chain/ethereum/modules/makerdao/vaults.py:233: error: Need type annotation for "starting_liabilities"
+ rotkehlchen/exchanges/binance.py:315: error: Need type annotation for "call_options"
+ rotkehlchen/chain/ethereum/modules/nfts.py:201: error: Argument 1 to "Asset" has incompatible type "Union[Any, Asset]"; expected "str"
+ rotkehlchen/db/upgrade_manager.py:299: error: Need type annotation for "kwargs"
+ rotkehlchen/globaldb/updates.py:422: error: Unsupported operand types for <= ("int" and "None")
+ rotkehlchen/globaldb/updates.py:422: note: Right operand is of type "Optional[Any]"
+ rotkehlchen/exchanges/kucoin.py:212: error: Need type annotation for "call_options"
+ rotkehlchen/exchanges/independentreserve.py:277: error: Need type annotation for "call_options"
+ rotkehlchen/exchanges/independentreserve.py:399: error: Need type annotation for "call_options"
+ rotkehlchen/exchanges/bittrex.py:213: error: Need type annotation for "given_options"
+ rotkehlchen/exchanges/bitstamp.py:335: error: Need type annotation for "call_options"
+ rotkehlchen/exchanges/bitpanda.py:438: error: Need type annotation for "given_options"
+ rotkehlchen/exchanges/bitfinex.py:170: error: Need type annotation for "call_options"
+ rotkehlchen/data_migrations/manager.py:51: error: Need type annotation for "kwargs"
+ rotkehlchen/api/rest.py:722: error: Need type annotation for "per_account"
+ rotkehlchen/tests/utils/rotkehlchen.py:209: error: Argument "poloniex_patch" to "BalancesTestSetup" has incompatible type "Optional[Any]"; expected "_patch[Any]"
+ rotkehlchen/tests/utils/rotkehlchen.py:210: error: Argument "binance_patch" to "BalancesTestSetup" has incompatible type "Optional[Any]"; expected "_patch[Any]"

bandersnatch (https://github.com/pypa/bandersnatch)
+ src/bandersnatch_storage_plugins/swift.py: note: In member "open_file" of class "SwiftStorage":
+ src/bandersnatch_storage_plugins/swift.py:768: error: Argument 1 to "StringIO" has incompatible type "Union[str, bytes]"; expected "Optional[str]"
+ src/bandersnatch_storage_plugins/swift.py:768: error: Argument 1 to "BytesIO" has incompatible type "Union[str, bytes]"; expected "bytes"

anyio (https://github.com/agronholm/anyio)
+ src/anyio/_backends/_asyncio.py:1010: error: Need type annotation for "kwargs"  [var-annotated]

vision (https://github.com/pytorch/vision)
+ torchvision/utils.py:243: error: Unsupported operand types for + ("int" and "Tuple[int]")  [operator]
+ torchvision/utils.py:243: note: Left operand is of type "Union[Any, Tuple[int, int, int], int]"
+ torchvision/datasets/cityscapes.py:194: error: Incompatible types in assignment (expression has type "Union[Tuple[Any, ...], Any]", variable has type "Dict[str, Any]")  [assignment]
+ torchvision/prototype/datasets/_builtin/mnist.py:46: error: Need type annotation for "shape"  [var-annotated]

pylint (https://github.com/pycqa/pylint)
+ pylint/checkers/utils.py:742: error: Need type annotation for "ancestors"  [var-annotated]
+ pylint/checkers/utils.py:846: error: Need type annotation for "decorators"  [var-annotated]
+ pylint/checkers/utils.py:1357: error: Need type annotation for "decorators"  [var-annotated]
+ pylint/checkers/base.py:373: error: Need type annotation for "decorators"  [var-annotated]

schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/models.py: note: In member "_get_headers" of class "Case":
+ src/schemathesis/models.py:258: error: Need type annotation for "final_headers"
+ src/schemathesis/extra/pytest_plugin.py: note: In member "_parametrize" of class "SchemathesisCase":
+ src/schemathesis/extra/pytest_plugin.py:171: error: Item "None" of "Optional[Any]" has no attribute "pytest_generate_tests"

git-revise (https://github.com/mystor/git-revise)
+ gitrevise/merge.py:55: error: Need type annotation for "new_parents"

schema_salad (https://github.com/common-workflow-language/schema_salad)
+ schema_salad/exceptions.py: note: In member "pretty_str" of class "SchemaSaladException":
+ schema_salad/exceptions.py:105:22: error: Need type annotation for "my_summary"  [var-annotated]
+ schema_salad/ref_resolver.py: note: In member "__init__" of class "Loader":
+ schema_salad/ref_resolver.py:167:13: error: Need type annotation for "foreign_properties"  [var-annotated]
+ schema_salad/ref_resolver.py:169:22: error: Need type annotation for "cache"  [var-annotated]

kopf (https://github.com/nolar/kopf)
+ kopf/_cogs/configs/conventions.py:147: error: Need type annotation for "v1_keys"

prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/run_configs/base.py:22: error: Need type annotation for "labels"
+ src/prefect/engine/state.py:906: error: Incompatible types in assignment (expression has type "List[State]", base class "State" defined the type as "List[Optional[Any]]")
+ src/prefect/engine/state.py:906: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ src/prefect/engine/state.py:906: note: Consider using "Sequence" instead, which is covariant
+ src/prefect/client/client.py:228: error: Need type annotation for "contents"
+ src/prefect/backend/flow_run.py:541: error: Argument "run_config" to "FlowRunView" has incompatible type "Optional[Any]"; expected "RunConfig"

zulip (https://github.com/zulip/zulip)
+ zerver/middleware.py:251: error: Need type annotation for "queries"  [var-annotated]
+ zerver/webhooks/github/view.py:494: error: Need type annotation for "requested_reviewer"  [var-annotated]
+ zerver/webhooks/github/view.py:496: error: Need type annotation for "requested_team"  [var-annotated]

sockeye (https://github.com/awslabs/sockeye)
+ sockeye/inference.py:1027: error: Need type annotation for "factors"

pip (https://github.com/pypa/pip)
+ src/pip/_internal/req/req_install.py:138: error: Need type annotation for "install_options"
+ src/pip/_internal/req/req_install.py:139: error: Need type annotation for "global_options"
+ src/pip/_internal/req/req_install.py:140: error: Need type annotation for "hash_options"

pyppeteer (https://github.com/pyppeteer/pyppeteer)
+ pyppeteer/page.py:1781: error: Need type annotation for "_args"
+ pyppeteer/network_manager.py:118: error: Need type annotation for "patterns"

tornado (https://github.com/tornadoweb/tornado)
+ tornado/template.py:316: error: Need type annotation for "namespace"
+ tornado/routing.py:474: error: Need type annotation for "target_kwargs"

spark (https://github.com/apache/spark)
+ python/pyspark/ml/tuning.py:119: error: Incompatible return value type (got "Tuple[int, float, Optional[Any]]", expected "Tuple[int, float, Transformer]")  [return-value]
+ python/pyspark/pandas/typedef/typehints.py:811: error: Incompatible types in assignment (expression has type "Union[Type[Any], Any]", variable has type "None")  [assignment]
+ python/pyspark/pandas/typedef/typehints.py:824: error: Incompatible types in assignment (expression has type "Union[Type[Any], Any]", variable has type "None")  [assignment]
+ python/pyspark/pandas/frame.py:473: error: Need type annotation for "_psseries"  [var-annotated]
+ python/pyspark/pandas/groupby.py:1446: error: Incompatible return value type (got "Tuple[DataFrame[Any], List[Tuple[Any, ...]], List[Union[Tuple[Any, ...], Any]]]", expected "Tuple[DataFrame[Any], List[Tuple[Any, ...]], List[str]]")  [return-value]

pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/config/argparsing.py:404: error: Need type annotation for "extra_info"  [var-annotated]
+ src/_pytest/terminal.py:1107: error: Need type annotation for "fskips"  [var-annotated]
+ src/_pytest/capture.py:598: error: Argument 1 to "CaptureResult" has incompatible type "Union[Any, str]"; expected "bytes"  [arg-type]
+ src/_pytest/capture.py:598: error: Argument 2 to "CaptureResult" has incompatible type "Union[Any, str]"; expected "bytes"  [arg-type]
+ testing/test_warnings.py:368: error: Need type annotation for "args"  [var-annotated]
+ testing/test_warnings.py:403: error: Need type annotation for "args"  [var-annotated]
+ testing/test_warnings.py:810: error: Need type annotation for "expected_extra"  [var-annotated]
+ testing/test_faulthandler.py:98: error: Need type annotation for "args"  [var-annotated]

jax (https://github.com/google/jax)
+ jax/interpreters/pxla.py:1206: error: Argument 2 to "local_avals_to_results_handler" has incompatible type "List[Union[AbstractValue, Any]]"; expected "Sequence[Optional[ShapedArray]]"  [arg-type]
+ jax/experimental/jax2tf/jax2tf.py:517: error: Need type annotation for "prev_constant_cache_keys"  [var-annotated]

ibis (https://github.com/ibis-project/ibis)
+ ibis/expr/scope.py:58: error: Need type annotation for "_items"

edgedb (https://github.com/edgedb/edgedb)
+ edb/schema/objects.py:2285: error: Unused "type: ignore" comment
+ edb/schema/referencing.py:315:13: error: Value of type variable "ObjectCommand_T" of "get_object_delta_command" cannot be "ObjectCommand[so.Object_T]"
+ edb/schema/referencing.py:315:13: error: Incompatible types in assignment (expression has type "ObjectCommand[so.Object_T]", variable has type "ObjectCommand[ReferencedInheritingObjectT]")
+ edb/schema/referencing.py:317: error: Unused "type: ignore" comment
+ edb/schema/inheriting.py:664:25: error: Tuple index out of range
+ edb/schema/delta.py:1225:28: error: Need type annotation for "_modaliases"
+ edb/schema/links.py:392:25: error: Argument 1 to "assignment_castable_to" of "Type" has incompatible type "Union[Any, Object]"; expected "Type"
+ edb/tools/mypy/plugin.py:63:20: error: Need type annotation for "mcls_mro"

steam.py (https://github.com/Gobot1234/steam.py)
- steam/image.py:88: error: Incompatible types in assignment (expression has type "object", variable has type "ImageIO")  [assignment]
+ steam/errors.py:161: error: Item "GCMsgHdr" of "Union[CMsgProtoBufHeader, ExtendedMsgHdr, MsgHdr, GCMsgHdr]" has no attribute "job_name_target"  [union-attr]
- steam/iterators.py:509: error: Argument 1 to "_append" of "AsyncIterator" has incompatible type "_GroupMessage"; expected "GroupMessages"  [arg-type]
+ steam/iterators.py:509: error: Argument 1 to "_append" of "AsyncIterator" has incompatible type "Union[GroupMessage, ClanMessage]"; expected "GroupMessages"  [arg-type]
- steam/gateway.py:373: error: Argument 2 to "run_parser" of "Registerable" has incompatible type "MsgBase[StructMessage]"; expected "Union[Union[MsgProto[Any], Msg[Any]], Union[GCMsgProto[Any], GCMsg[Any]]]"  [arg-type]
+ steam/channel.py:162: error: Incompatible types in assignment (expression has type "_GroupMessage", variable has type "Union[ClanMessage, GroupMessage]")  [assignment]
+ steam/channel.py:170: error: Incompatible types in assignment (expression has type "M_co", variable has type "Union[ClanMessage, GroupMessage]")  [assignment]
- steam/channel.py:162: error: No overload variant of "__new__" of "type" matches argument type "type"  [call-overload]
- steam/channel.py:162: note: Possible overload variants:
- steam/channel.py:162: note:     def __new__(cls, cls: Type[type], object) -> type
- steam/channel.py:162: note:     def [_TT <: type] __new__(cls, cls: Type[_TT], str, Tuple[type, ...], Dict[str, Any], **kwds: Any) -> _TT
+ steam/state.py:137: error: Need type annotation for "games"  [var-annotated]
- steam/ext/_gc/state.py:63: error: Argument 2 to "run_parser" of "Registerable" has incompatible type "MsgBase[StructMessage]"; expected "Union[Union[MsgProto[Any], Msg[Any]], Union[GCMsgProto[Any], GCMsg[Any]]]"  [arg-type]
+ steam/client.py:786: error: Need type annotation for "games_"  [var-annotated]
- steam/ext/commands/converters.py:328: error: Argument 1 to "find" has incompatible type "Callable[[_GroupChannel[_GroupMessage]], object]"; expected "Callable[[_GroupChannel[_GroupMessage]], bool]"  [arg-type]
+ steam/ext/commands/converters.py:328: error: Argument 1 to "find" has incompatible type "Callable[[_GroupChannel[_GroupMessage]], Union[bool, Callable[[Any], Any]]]"; expected "Callable[[_GroupChannel[_GroupMessage]], bool]"  [arg-type]
- steam/ext/commands/converters.py:328: error: Incompatible return value type (got "object", expected "bool")  [return-value]
+ steam/ext/commands/converters.py:328: error: Incompatible return value type (got "Union[bool, Callable[[Any], Any]]", expected "bool")  [return-value]
- steam/ext/commands/commands.py:212: error: Incompatible return value type (got "object", expected "CallbackType[P]")  [return-value]
+ steam/ext/commands/commands.py:212: error: Incompatible return value type (got "Union[FunctionType, CallbackType[P]]", expected "CallbackType[P]")  [return-value]
+ steam/ext/commands/commands.py:224: error: Item "CallbackType[P]" of "Union[FunctionType, CallbackType[P]]" has no attribute "__globals__"  [union-attr]
- steam/ext/commands/commands.py:224: error: "object" has no attribute "__globals__"  [attr-defined]
- steam/ext/commands/commands.py:228: error: Argument 1 to "signature" has incompatible type "object"; expected "Callable[..., Any]"  [arg-type]
- steam/ext/commands/commands.py:619: error: Incompatible types in assignment (expression has type "object", variable has type "Dict[str, Command[Any]]")  [assignment]
+ steam/ext/commands/commands.py:1093: error: Incompatible return value type (got "Union[MCD, CheckReturnType]", expected "MCD")  [return-value]
+ steam/ext/commands/commands.py:1118: error: Incompatible return value type (got "Union[MCD, CheckReturnType]", expected "MCD")  [return-value]
- steam/ext/commands/cog.py:166: error: Incompatible return value type (got "object", expected "Callable[[E], E]")  [return-value]
+ steam/ext/commands/cog.py:166: error: Incompatible return value type (got "Union[E, Callable[[E], E]]", expected "Callable[[E], E]")  [return-value]
- steam/ext/commands/bot.py:432: error: Incompatible return value type (got "object", expected "Callable[[E], E]")  [return-value]
+ steam/ext/commands/bot.py:432: error: Incompatible return value type (got "Union[E, Callable[[E], E]]", expected "Callable[[E], E]")  [return-value]

werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/routing.py:1025: error: Incompatible return value type (got "List[Union[stmt, Str]]", expected "List[AST]")  [return-value]
+ src/werkzeug/routing.py:1025: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ src/werkzeug/routing.py:1025: note: Consider using "Sequence" instead, which is covariant
+ src/werkzeug/routing.py:1025: note: Perhaps you need a type annotation for "ret"? Suggestion: "List[AST]"

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/jinja2glue.py: note: In member "init" of class "BuiltinTemplateLoader":
+ sphinx/jinja2glue.py:173:22: error: Need type annotation for "extensions"
+ sphinx/ext/autodoc/__init__.py: note: In member "parse_name" of class "Documenter":
+ sphinx/ext/autodoc/__init__.py:403:23: error: Need type annotation for "parents"
+ sphinx/ext/doctest.py: note: In member "test_group" of class "DocTestBuilder":
+ sphinx/ext/doctest.py:527:27: error: Need type annotation for "options"
+ sphinx/testing/fixtures.py: note: In function "test_params":
+ sphinx/testing/fixtures.py:120:14: error: Need type annotation for "kwargs"

spack (https://github.com/spack/spack)
+ lib/spack/spack/util/environment.py:37: error: Need type annotation for "suffixes"

isort (https://github.com/pycqa/isort)
+ isort/parse.py:275: error: Need type annotation for "comments"

pyinstrument (https://github.com/joerick/pyinstrument)
- pyinstrument/renderers/console.py:77: error: "Type[object]" has no attribute "end"
- pyinstrument/renderers/console.py:79: error: "Type[object]" has no attribute "end"
- pyinstrument/renderers/console.py:79: error: "Type[object]" has no attribute "faint"
- pyinstrument/renderers/console.py:93: error: "Type[object]" has no attribute "faint"
- pyinstrument/renderers/console.py:93: error: "Type[object]" has no attribute "end"
- pyinstrument/renderers/console.py:123: error: "Type[object]" has no attribute "red"
- pyinstrument/renderers/console.py:125: error: "Type[object]" has no attribute "yellow"
- pyinstrument/renderers/console.py:127: error: "Type[object]" has no attribute "green"
- pyinstrument/renderers/console.py:129: error: "Type[object]" has no attribute "bright_green"
- pyinstrument/renderers/console.py:129: error: "Type[object]" has no attribute "faint"
- pyinstrument/renderers/console.py:133: error: "Type[object]" has no attribute "bg_dark_blue_255"
- pyinstrument/renderers/console.py:133: error: "Type[object]" has no attribute "white_255"

Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/dependencies/owners.py:174: error: Returning Any from function declared to return "bool"  [no-any-return]
- tanjun/dependencies/owners.py:184: error: Returning Any from function declared to return "bool"  [no-any-return]

xarray (https://github.com/pydata/xarray)
+ xarray/core/dataset.py:810: error: Need type annotation for "kwargs"  [var-annotated]
+ xarray/core/weighted.py:129: error: Need type annotation for "dims"  [var-annotated]
+ xarray/backends/api.py:1047: error: Need type annotation for "kwargs"  [var-annotated]

freqtrade (https://github.com/freqtrade/freqtrade)
+ freqtrade/exchange/exchange.py:1205: error: Need type annotation for "_params"

manticore (https://github.com/trailofbits/manticore)
+ manticore/wasm/structure.py:1975: error: Need type annotation for "advice"
+ manticore/native/manticore.py:296: error: Incompatible types in assignment (expression has type "Callable[[Any, Any], Any]", variable has type "Union[Callable[[Any, Any, Any], Any], Callable[[Any, Any, Any, Any], Any]]")

optuna (https://github.com/optuna/optuna)
+ optuna/visualization/_pareto_front.py:283: error: Need type annotation for "user_attrs_dict"

core (https://github.com/home-assistant/core)
+ homeassistant/data_entry_flow.py:99: error: Incompatible types (expression has type "Optional[Any]", TypedDict item "step_id" has type "str")  [typeddict-item]
+ homeassistant/helpers/translation.py:266: error: Unused "type: ignore" comment
+ homeassistant/helpers/service.py:85: error: Need type annotation for "entity_ids"  [var-annotated]
+ homeassistant/helpers/service.py:88: error: Need type annotation for "device_ids"  [var-annotated]
+ homeassistant/helpers/service.py:90: error: Need type annotation for "area_ids"  [var-annotated]
+ homeassistant/components/mqtt/subscription.py:88: error: Need type annotation for "current_subscriptions"  [var-annotated]
+ homeassistant/helpers/helper_config_entry_flow.py:47: error: Need type annotation for "_options"  [var-annotated]
+ homeassistant/components/tts/__init__.py:139: error: Need type annotation for "conf"  [var-annotated]
+ homeassistant/components/modbus/modbus.py:377: error: Need type annotation for "kwargs"  [var-annotated]
- homeassistant/components/shelly/__init__.py:436: error: Returning Any from function declared to return "str"  [no-any-return]
- homeassistant/components/shelly/__init__.py:723: error: Returning Any from function declared to return "str"  [no-any-return]
+ homeassistant/components/picnic/sensor.py:70: error: Need type annotation for "data_set"  [var-annotated]
+ homeassistant/components/picnic/coordinator.py:113: error: Need type annotation for "next_delivery"  [var-annotated]
+ homeassistant/components/picnic/coordinator.py:115: error: Need type annotation for "last_order"  [var-annotated]
+ homeassistant/components/mqtt/siren.py:308: error: Need type annotation for "attributes"  [var-annotated]
+ homeassistant/components/keenetic_ndms2/device_tracker.py:129: error: Incompatible return value type (got "Optional[Any]", expected "str")  [return-value]
+ homeassistant/components/keenetic_ndms2/config_flow.py:84: error: Need type annotation for "host_schema"  [var-annotated]
+ homeassistant/components/geniushub/sensor.py:97: error: Incompatible return value type (got "Union[Any, int]", expected "str")  [return-value]
+ homeassistant/components/fritz/switch.py:574: error: Incompatible types in assignment (expression has type "Optional[Any]", target has type "str")  [assignment]
+ homeassistant/components/accuweather/__init__.py:101: error: Need type annotation for "forecast"  [var-annotated]
+ homeassistant/components/zwave_js/sensor.py:353: error: Need type annotation for "args"  [var-annotated]
- homeassistant/components/knx/climate.py:176: error: Returning Any from function declared to return "float"  [no-any-return]
- homeassistant/components/knx/climate.py:182: error: Returning Any from function declared to return "float"  [no-any-return]
+ homeassistant/components/heos/media_player.py:385: error: Incompatible return value type (got "Optional[Any]", expected "str")  [return-value]

black (https://github.com/psf/black)
+ src/black/trans.py:1204:35: error: Need type annotation for "maybe_prefix_leaves"

dragonchain (https://github.com/dragonchain/dragonchain)
+ dragonchain/lib/party.py:58:15: error: Need type annotation for "headers"
+ dragonchain/webserver/lib/verifications.py:85:12: error: Incompatible return value type (got "Optional[Any]", expected "str")
- dragonchain/job_processor/contract_job.py:307:24: error: Unexpected keyword argument "headers"
- dragonchain/job_processor/contract_job.py:307:24: error: Unexpected keyword argument "json"
- dragonchain/job_processor/contract_job.py:344:20: error: Unexpected keyword argument "headers"
- dragonchain/job_processor/contract_job.py:344:20: error: Unexpected keyword argument "json"

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/indexers/objects.py:324: error: Need type annotation for "indexer_kwargs"  [var-annotated]
+ pandas/core/arrays/sparse/dtype.py:416: error: Argument 1 to "find_common_type" has incompatible type "List[Union[Any, dtype[Any], ExtensionDtype]]"; expected "Iterable[Union[dtype[Any], None, Type[Any], _SupportsDType[dtype[Any]], str, Union[Tuple[Any, int], Tuple[Any, Union[SupportsIndex, Sequence[SupportsIndex]]], List[Any], _DTypeDict, Tuple[Any, Any]]]]"  [arg-type]
+ pandas/core/computation/ops.py:86: error: Unused "type: ignore" comment
+ pandas/core/nanops.py:785: error: Incompatible types in assignment (expression has type "Union[Any, float]", variable has type "ndarray[Any, dtype[Any]]")  [assignment]
+ pandas/core/ops/array_ops.py:395: error: Unused "type: ignore" comment
+ pandas/core/arrays/sparse/array.py:470: error: Argument 1 to "na_value_for_dtype" has incompatible type "Union[Any, ExtensionDtype, dtype[Any], Type[object]]"; expected "Union[dtype[Any], ExtensionDtype]"  [arg-type]
+ pandas/plotting/_core.py:964: error: Argument 1 to "len" has incompatible type "Union[Any, bool]"; expected "Sized"  [arg-type]
+ pandas/core/indexes/interval.py:522: error: Unused "type: ignore" comment
+ pandas/io/pytables.py:4551: error: Need type annotation for "info"  [var-annotated]
+ pandas/core/reshape/merge.py:723: error: Need type annotation for "lindexers"  [var-annotated]
+ pandas/core/reshape/merge.py:724: error: Need type annotation for "rindexers"  [var-annotated]
+ pandas/core/reshape/merge.py:1676: error: Need type annotation for "lindexers"  [var-annotated]
+ pandas/core/reshape/merge.py:1677: error: Need type annotation for "rindexers"  [var-annotated]
+ pandas/core/internals/blocks.py:575: error: Item "ndarray[Any, Any]" of "Union[ndarray[Any, Any], ExtensionArray, Any]" has no attribute "_replace"  [union-attr]
+ pandas/core/internals/blocks.py:575: error: Item "ExtensionArray" of "Union[ndarray[Any, Any], ExtensionArray, Any]" has no attribute "_replace"  [union-attr]
+ pandas/core/internals/blocks.py:728: error: Argument "mask" to "_replace_coerce" of "Block" has incompatible type "Union[ExtensionArray, ndarray[Any, Any], bool]"; expected "ndarray[Any, dtype[bool_]]"  [arg-type]
+ pandas/io/formats/style_render.py:894: error: Unsupported operand types for + ("List[Dict[str, Union[List[Tuple[str, Union[str, int, float]]], Any, str]]]" and "List[Dict[str, List[Tuple[str, Union[str, int, float]]]]]")  [operator]
+ pandas/io/formats/style.py:1064```

@JelleZijlstra
Copy link
Member Author

Notes:

@jhance
Copy link
Collaborator

jhance commented Mar 21, 2022

Random commentary: I think if we do this it should be behind a flag at first. Then we can flip the default and eventually remove later to decouple this from people updating mypy. Unless I'm overestimating how breaking this is.

We also need to verify switching the behavior will work for us internally

@JukkaL
Copy link
Collaborator

JukkaL commented Mar 21, 2022

@JelleZijlstra

A lot of "Need type annotation" for code of the form [non, empty] if something else []. We probably need to provide some type context for the else branch in this case. This also affects the self-check.

Most of the errors seem to be of this kind. If we can fix this, the number of remaining regressions might not be too bad.

@jhance

I think if we do this it should be behind a flag at first.

Let's wait until we see how many regressions remain. If the number of regressions is high enough, this could be a good option, but if it's only, say, a few dozen, this may not be needed.

@JelleZijlstra
Copy link
Member Author

#12712 does it better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants