Skip to content

[red-knot] basic narrowing on attribute and subscript expressions #17643

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mtshiba
Copy link
Contributor

@mtshiba mtshiba commented Apr 26, 2025

Summary

This PR closes astral-sh/ty#164.

This PR introduces a basic type narrowing mechanism for attribute/subscript expressions.
Member accesses, int literal subscripts, string literal subscripts are supported (same as mypy and pyright).

Advanced narrowing mechanisms, such as the following, are not implemented in this PR (and will be future works):

  • narrowing by overwriting assignments
class C:
    def __init__(self):
        self.x: int | None = None
        self.y: list[int | None] = [None]

c = C()
c.x = 0
c.y[0] = 0
reveal_type(c.x)  # Literal[0]
reveal_type(c.y[0])  # Literal[0]
  • narrowing by other elements
def f(t: tuple[int, int] | tuple[None, None]):
    if t[0] is not None:
        reveal_type(t[1])  # int

Test Plan

New test cases are added to mdtest/narrow/composite_target.md.

Copy link
Contributor

github-actions bot commented Apr 26, 2025

mypy_primer results

Changes were detected when running on open source projects
com2ann (https://github.com/ilevkivskyi/com2ann)
- error[lint:invalid-argument-type] src/com2ann.py:163:32: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] src/com2ann.py:166:32: Argument to this function is incorrect: Expected `int`, found `int | None`
- error[lint:invalid-argument-type] src/com2ann.py:166:50: Argument to this function is incorrect: Expected `int`, found `int | None`
- Found 9 diagnostics
+ Found 6 diagnostics

mypy_primer (https://github.com/hauntsaninja/mypy_primer)
- error[lint:invalid-argument-type] mypy_primer/main.py:130:39: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:unsupported-operator] mypy_primer/main.py:168:23: Operator `*` is unsupported between objects of type `list` and `int | None`
- error[lint:no-matching-overload] mypy_primer/main.py:169:60: No overload of function `__new__` matches arguments
- error[lint:no-matching-overload] mypy_primer/main.py:175:29: No overload of function `__new__` matches arguments
- error[lint:unsupported-operator] mypy_primer/main.py:238:16: Operator `+` is unsupported between objects of type `Literal["timer_"]` and `str | None`
- Found 18 diagnostics
+ Found 13 diagnostics

beartype (https://github.com/beartype/beartype)
- warning[lint:possibly-unbound-attribute] beartype/_check/error/_pep/errpep484604.py:127:16: Attribute `startswith` on type `str | None` is possibly unbound
- warning[lint:call-possibly-unbound-method] beartype/_check/error/_pep/errpep484604.py:135:29: Method `__getitem__` of type `str | None` is possibly unbound
- error[lint:invalid-argument-type] beartype/_check/error/errmain.py:504:9: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:unsupported-operator] beartype/_check/logic/logcls.py:546:18: Operator `%` is unsupported between objects of type `int | None` and `int`
- Found 556 diagnostics
+ Found 552 diagnostics

nionutils (https://github.com/nion-software/nionutils)
- warning[lint:call-possibly-unbound-method] nion/utils/Event.py:106:68: Method `__getitem__` of type `Unknown | StackSummary | None` is possibly unbound
- warning[lint:redundant-cast] nion/utils/StructuredModel.py:124:20: Value is already of type `Unknown`
- Found 33 diagnostics
+ Found 31 diagnostics

pegen (https://github.com/we-like-parsers/pegen)
- warning[lint:possibly-unbound-attribute] src/pegen/parser_generator.py:39:26: Attribute `startswith` on type `Unknown | str | None` is possibly unbound
- Found 55 diagnostics
+ Found 54 diagnostics

python-chess (https://github.com/niklasf/python-chess)
- error[lint:unsupported-operator] chess/engine.py:1511:45: Operator `*` is unsupported between objects of type `int | float | None` and `Literal[1000]`
- error[lint:unsupported-operator] chess/engine.py:1514:45: Operator `*` is unsupported between objects of type `int | float | None` and `Literal[1000]`
- error[lint:unsupported-operator] chess/engine.py:1517:38: Operator `*` is unsupported between objects of type `int | float | None` and `Literal[1000]`
- error[lint:unsupported-operator] chess/engine.py:1520:38: Operator `*` is unsupported between objects of type `int | float | None` and `Literal[1000]`
- error[lint:unsupported-operator] chess/engine.py:1535:45: Operator `*` is unsupported between objects of type `int | float | None` and `Literal[1000]`
- error[lint:unsupported-operator] chess/engine.py:1634:29: Operator `+=` is unsupported between objects of type `None` and `(int & ~AlwaysFalsy) | float`
- error[lint:unsupported-operator] chess/engine.py:1638:29: Operator `+=` is unsupported between objects of type `None` and `(int & ~AlwaysFalsy) | float`
- error[lint:unsupported-operator] chess/engine.py:1642:29: Operator `-=` is unsupported between objects of type `None` and `Literal[1]`
- error[lint:unsupported-operator] chess/engine.py:2207:105: Operator `*` is unsupported between objects of type `int | float | None` and `Literal[100]`
- error[lint:unsupported-operator] chess/engine.py:2209:105: Operator `*` is unsupported between objects of type `int | float | None` and `Literal[100]`
- error[lint:invalid-argument-type] chess/engine.py:2393:64: Argument to this function is incorrect: Expected `int`, found `int | None`
- error[lint:invalid-argument-type] chess/gaviota.py:1892:35: Argument to this function is incorrect: Expected `int`, found `@Todo(Support for `typing.TypeAlias`) | None | Literal[64]`
- error[lint:call-non-callable] chess/polyglot.py:256:44: Method `__getitem__` of type `Overload[(i: SupportsIndex, /) -> _T, (s: slice[Any, _StartT_co, _StartT_co | _StopT_co], /) -> @Todo(specialized non-generic class)]` is not callable on object of type `list`
- error[lint:call-non-callable] chess/polyglot.py:258:42: Method `__getitem__` of type `Overload[(i: SupportsIndex, /) -> _T, (s: slice[Any, _StartT_co, _StartT_co | _StopT_co], /) -> @Todo(specialized non-generic class)]` is not callable on object of type `list`
- error[lint:invalid-argument-type] chess/polyglot.py:262:59: Argument to this function is incorrect: Expected `int`, found `@Todo(Support for `typing.TypeAlias`) | None`
- Found 60 diagnostics
+ Found 45 diagnostics

pyp (https://github.com/hauntsaninja/pyp)
- warning[lint:possibly-unbound-attribute] pyp.py:105:16: Attribute `id` on type `Name | Attribute | Subscript` is possibly unbound
- warning[lint:possibly-unbound-attribute] pyp.py:106:36: Attribute `id` on type `Name | Attribute | Subscript` is possibly unbound
- Found 17 diagnostics
+ Found 15 diagnostics

aioredis (https://github.com/aio-libs/aioredis)
- error[lint:invalid-argument-type] aioredis/connection.py:1208:38: Argument to this function is incorrect: Expected `str | bytes`, found `str | None`
- error[lint:invalid-argument-type] aioredis/connection.py:1210:38: Argument to this function is incorrect: Expected `str | bytes`, found `str | None`
- error[lint:invalid-argument-type] aioredis/connection.py:1220:38: Argument to this function is incorrect: Expected `str | bytes`, found `str | None`
- Found 28 diagnostics
+ Found 25 diagnostics

pyinstrument (https://github.com/joerick/pyinstrument)
- error[lint:unsupported-operator] pyinstrument/__main__.py:52:31: Operator `+` is unsupported between objects of type `@Todo(specialized non-generic class) | None` and `@Todo(specialized non-generic class) | None`
- warning[lint:call-possibly-unbound-method] pyinstrument/__main__.py:53:9: Method `__getitem__` of type `@Todo(specialized non-generic class) | None` is possibly unbound
- warning[lint:call-possibly-unbound-method] pyinstrument/__main__.py:54:9: Method `__getitem__` of type `@Todo(specialized non-generic class) | None` is possibly unbound
- error[lint:invalid-argument-type] pyinstrument/__main__.py:56:32: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] pyinstrument/__main__.py:332:49: Argument to this function is incorrect: Expected `str`, found `str | None`
- warning[lint:possibly-unbound-attribute] pyinstrument/__main__.py:342:21: Attribute `value` on type `ValueWithRemainingArgs | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] pyinstrument/__main__.py:342:45: Attribute `remaining_args` on type `ValueWithRemainingArgs | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] pyinstrument/__main__.py:344:65: Attribute `value` on type `ValueWithRemainingArgs | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] pyinstrument/__main__.py:346:28: Attribute `remaining_args` on type `ValueWithRemainingArgs | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] pyinstrument/__main__.py:347:20: Attribute `value` on type `ValueWithRemainingArgs | None` is possibly unbound
- error[lint:invalid-argument-type] pyinstrument/__main__.py:445:40: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] pyinstrument/__main__.py:458:40: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:not-iterable] pyinstrument/__main__.py:487:32: Object of type `@Todo(specialized non-generic class) | None` may not be iterable
- error[lint:invalid-argument-type] pyinstrument/__main__.py:533:48: Argument to this function is incorrect: Expected `str`, found `str | None`
- warning[lint:possibly-unbound-attribute] pyinstrument/frame.py:378:13: Attribute `remove_frame` on type `FrameGroup | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] pyinstrument/frame_ops.py:149:9: Attribute `remove_frame` on type `FrameGroup | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] pyinstrument/frame_ops.py:151:16: Attribute `frames` on type `FrameGroup | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] pyinstrument/frame_ops.py:154:13: Attribute `remove_frame` on type `FrameGroup | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] pyinstrument/frame_ops.py:154:32: Attribute `frames` on type `FrameGroup | None` is possibly unbound
- error[lint:no-matching-overload] pyinstrument/processors.py:252:17: No overload of function `match` matches arguments
- error[lint:unsupported-operator] pyinstrument/processors.py:260:17: Operator `in` is not supported for types `str` and `None`, in comparing `Literal["<string>"]` with `str | None`
- error[lint:no-matching-overload] pyinstrument/processors.py:268:18: No overload of function `match` matches arguments
- error[lint:unsupported-operator] pyinstrument/processors.py:268:62: Operator `in` is not supported for types `str` and `None`, in comparing `Literal["<frozen runpy>"]` with `str | None`
- warning[lint:possibly-unbound-attribute] pyinstrument/renderers/console.py:128:13: Attribute `root` on type `FrameGroup | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] pyinstrument/renderers/console.py:130:25: Attribute `exit_frames` on type `FrameGroup | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] pyinstrument/renderers/console.py:171:21: Attribute `root` on type `FrameGroup | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] pyinstrument/renderers/jsonrenderer.py:58:65: Attribute `id` on type `FrameGroup | None` is possibly unbound
- error[lint:invalid-argument-type] pyinstrument/renderers/jsonrenderer.py:61:67: Argument to this function is incorrect: Expected `str`, found `str | None`
- Found 97 diagnostics
+ Found 69 diagnostics

git-revise (https://github.com/mystor/git-revise)
- error[lint:invalid-argument-type] gitrevise/tui.py:126:40: Argument to this function is incorrect: Expected `Commit`, found `Commit | None`
- error[lint:invalid-argument-type] gitrevise/tui.py:128:47: Argument to this function is incorrect: Expected `Commit`, found `Commit | None`
- error[lint:invalid-argument-type] gitrevise/tui.py:128:47: Argument to this function is incorrect: Expected `Commit`, found `Commit | None`
- error[lint:invalid-argument-type] gitrevise/tui.py:128:47: Argument to this function is incorrect: Expected `Commit`, found `Commit | None`
- error[lint:invalid-argument-type] gitrevise/tui.py:180:39: Argument to this function is incorrect: Expected `Commit`, found `Commit | None`
- warning[lint:possibly-unbound-attribute] gitrevise/tui.py:183:13: Attribute `tree` on type `Commit | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] gitrevise/utils.py:238:18: Attribute `oid` on type `Commit | None` is possibly unbound
- Found 14 diagnostics
+ Found 7 diagnostics

anyio (https://github.com/agronholm/anyio)
- error[lint:invalid-assignment] src/anyio/_backends/_asyncio.py:386:13: Object of type `BaseException | None` is not assignable to `CancelledError`
- error[lint:unsupported-operator] src/anyio/_backends/_asyncio.py:579:25: Operator `+=` is unsupported between objects of type `None` and `Literal[1]`
- warning[lint:possibly-unbound-attribute] src/anyio/_backends/_asyncio.py:797:29: Attribute `_tasks` on type `Unknown | CancelScope | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/anyio/_backends/_asyncio.py:798:13: Attribute `_tasks` on type `Unknown | CancelScope | None` is possibly unbound
- error[lint:invalid-argument-type] src/anyio/_backends/_asyncio.py:2469:41: Argument to this function is incorrect: Expected `tuple[Context, (...) -> Unknown, tuple, Future, CancelScope] | None`, found `tuple[Context, (...) -> T_Retval, @Todo(full tuple[...] support), Unknown, CancelScope | None]`
- Found 137 diagnostics
+ Found 132 diagnostics

kopf (https://github.com/nolar/kopf)
- warning[lint:possibly-unbound-attribute] kopf/_cogs/clients/watching.py:93:35: Attribute `get` on type `RawStatusDetails | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] kopf/_cogs/structs/credentials.py:367:24: Attribute `values` on type `dict[str, object] | None` is possibly unbound
- error[lint:unsupported-operator] kopf/_core/actions/execution.py:268:44: Operator `>=` is not supported for types `int` and `None`, in comparing `int | float` with `int | float | None`
- error[lint:unsupported-operator] kopf/_core/actions/execution.py:271:44: Operator `>=` is not supported for types `int` and `None`, in comparing `int` with `int | None`
- error[lint:invalid-argument-type] kopf/_core/actions/progression.py:116:46: Argument to this function is incorrect: Expected `int | float`, found `int | float | None`
- error[lint:unsupported-operator] kopf/_core/actions/throttlers.py:36:26: Operator `-` is unsupported between objects of type `int | float | None` and `int | float`
- error[lint:unsupported-operator] kopf/_core/actions/throttlers.py:76:26: Operator `-` is unsupported between objects of type `int | float | None` and `int | float`
- error[lint:call-non-callable] kopf/_core/engines/admission.py:270:36: Object of type `None` is not callable
- error[lint:invalid-argument-type] kopf/_core/engines/admission.py:367:17: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] kopf/_core/engines/admission.py:384:17: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] kopf/_core/engines/daemons.py:94:17: Argument to this function is incorrect: Expected `Body`, found `Body | None`
- error[lint:no-matching-overload] kopf/_core/engines/daemons.py:386:18: No overload of function `__new__` matches arguments
- error[lint:unsupported-operator] kopf/_core/engines/daemons.py:551:44: Operator `<` is not supported for types `int` and `None`, in comparing `int | float` with `int | float | None`
- error[lint:unsupported-operator] kopf/_core/engines/daemons.py:552:25: Operator `+` is unsupported between objects of type `int | float` and `int | float | None`
- error[lint:unsupported-operator] kopf/_core/engines/daemons.py:589:51: Operator `%` is unsupported between objects of type `int | float` and `int | float | None`
- warning[lint:possibly-unbound-attribute] kopf/_core/intents/registries.py:418:13: Attribute `check` on type `Selector | None` is possibly unbound
- error[lint:call-non-callable] kopf/_core/intents/registries.py:538:36: Object of type `None` is not callable
- error[lint:call-non-callable] kopf/_core/intents/registries.py:544:36: Object of type `None` is not callable
- error[lint:call-non-callable] kopf/_core/intents/registries.py:558:12: Object of type `None` is not callable
- error[lint:invalid-argument-type] kopf/_core/reactor/processing.py:443:81: Argument to this function is incorrect: Expected `BodyEssence`, found `@Todo(TypedDict) | None`
- error[lint:invalid-argument-type] kopf/_core/reactor/running.py:476:33: Argument to this function is incorrect: Expected `int | float`, found `int | float | None`
- error[lint:invalid-argument-type] kopf/cli.py:104:41: Argument to this function is incorrect: Expected `OperatorRegistry`, found `OperatorRegistry | None`
- Found 226 diagnostics
+ Found 204 diagnostics

kornia (https://github.com/kornia/kornia)
- error[lint:not-iterable] kornia/augmentation/container/image.py:380:18: Object of type `dict[Unknown, Unknown] | list | None` may not be iterable
- error[lint:unsupported-operator] kornia/augmentation/container/image.py:382:10: Operator `in` is not supported for types `str` and `None`, in comparing `Literal["output_size"]` with `dict[Unknown, Unknown] | list | None`
- error[lint:call-non-callable] kornia/augmentation/container/image.py:383:17: Method `__getitem__` of type `(bound method dict[Unknown, Unknown].__getitem__(key: Unknown, /) -> Unknown) | (Overload[(i: SupportsIndex, /) -> _T, (s: slice[Any, _StartT_co, _StartT_co | _StopT_co], /) -> @Todo(specialized non-generic class)])` is not callable on object of type `dict[Unknown, Unknown] | list | None`
- error[lint:call-non-callable] kornia/augmentation/container/image.py:388:32: Method `__getitem__` of type `(bound method dict[Unknown, Unknown].__getitem__(key: Unknown, /) -> Unknown) | (Overload[(i: SupportsIndex, /) -> _T, (s: slice[Any, _StartT_co, _StartT_co | _StopT_co], /) -> @Todo(specialized non-generic class)])` is not callable on object of type `dict[Unknown, Unknown] | list | None`
- error[lint:invalid-return-type] kornia/augmentation/container/ops.py:50:16: Return type does not match returned value: Expected `dict[Unknown, Unknown]`, found `dict[Unknown, Unknown] | list | None`
- error[lint:invalid-return-type] kornia/augmentation/container/ops.py:58:16: Return type does not match returned value: Expected `list`, found `dict[Unknown, Unknown] | list | None`
- error[lint:invalid-argument-type] kornia/contrib/models/rt_detr/model.py:220:35: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] kornia/contrib/models/sam/model.py:210:17: Argument to this function is incorrect: Expected `int`, found `int | None`
- error[lint:invalid-argument-type] kornia/contrib/models/sam/model.py:211:17: Argument to this function is incorrect: Expected `int`, found `int | None`
- Found 963 diagnostics
+ Found 954 diagnostics

graphql-core (https://github.com/graphql-python/graphql-core)
- warning[lint:possibly-unbound-attribute] src/graphql/execution/collect_fields.py:362:12: Attribute `value` on type `NameNode | None` is possibly unbound
- error[lint:call-non-callable] src/graphql/execution/execute.py:1230:26: Object of type `None` is not callable
- warning[lint:possibly-unbound-attribute] src/graphql/type/validate.py:496:36: Attribute `type` on type `InputValueDefinitionNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/graphql/utilities/extend_schema.py:564:25: Attribute `value` on type `StringValueNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/graphql/utilities/extend_schema.py:701:25: Attribute `value` on type `StringValueNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/graphql/utilities/extend_schema.py:720:25: Attribute `value` on type `StringValueNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/graphql/utilities/extend_schema.py:736:25: Attribute `value` on type `StringValueNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/graphql/utilities/extend_schema.py:751:25: Attribute `value` on type `StringValueNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/graphql/utilities/extend_schema.py:764:25: Attribute `value` on type `StringValueNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/graphql/utilities/extend_schema.py:781:25: Attribute `value` on type `StringValueNode | None` is possibly unbound
- warning[lint:call-possibly-unbound-method] src/graphql/utilities/introspection_from_schema.py:50:15: Method `__getitem__` of type `@Todo(specialized non-generic class) | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/graphql/validation/rules/no_undefined_variables.py:44:43: Attribute `value` on type `NameNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/graphql/validation/rules/no_unused_variables.py:47:43: Attribute `value` on type `NameNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/graphql/validation/rules/single_field_subscriptions.py:41:30: Attribute `value` on type `NameNode | None` is possibly unbound
- warning[lint:call-possibly-unbound-method] tests/error/test_graphql_error.py:260:16: Method `__getitem__` of type `@Todo(specialized non-generic class) | None` is possibly unbound
- warning[lint:call-possibly-unbound-method] tests/error/test_graphql_error.py:261:9: Method `__getitem__` of type `@Todo(specialized non-generic class) | None` is possibly unbound
- warning[lint:call-possibly-unbound-method] tests/execution/test_resolve.py:316:17: Method `__getitem__` of type `@Todo(specialized non-generic class) | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/language/test_parser.py:634:16: Attribute `source` on type `Location | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/language/test_parser.py:638:38: Attribute `start_token` on type `Location | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/language/test_parser.py:641:36: Attribute `end_token` on type `Location | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/language/test_parser.py:654:38: Attribute `start_token` on type `Location | None` is possibly unbound
- warning[lint:call-possibly-unbound-method] tests/pyutils/test_description.py:202:30: Method `__getitem__` of type `dict[str, Any] | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/utilities/test_build_ast_schema.py:1114:16: Attribute `name` on type `GraphQLObjectType | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/utilities/test_build_ast_schema.py:1116:16: Attribute `name` on type `GraphQLObjectType | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/utilities/test_build_ast_schema.py:1118:16: Attribute `name` on type `GraphQLObjectType | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/utilities/test_build_ast_schema.py:1130:16: Attribute `name` on type `GraphQLObjectType | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/utilities/test_build_ast_schema.py:1132:16: Attribute `name` on type `GraphQLObjectType | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/utilities/test_build_ast_schema.py:1134:16: Attribute `name` on type `GraphQLObjectType | None` is possibly unbound
- Found 552 diagnostics
+ Found 524 diagnostics

speedrun.com_global_scoreboard_webapp (https://github.com/Avasam/speedrun.com_global_scoreboard_webapp)
- warning[lint:call-possibly-unbound-method] backend/models/global_scoreboard_models.py:93:101: Method `__getitem__` of type `Unknown | None` is possibly unbound
- Found 122 diagnostics
+ Found 121 diagnostics

strawberry (https://github.com/strawberry-graphql/strawberry)
- warning[lint:possibly-unbound-attribute] strawberry/codegen/plugins/python.py:194:58: Attribute `__name__` on type `type | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/codegen/query_codegen.py:375:17: Attribute `value` on type `NameNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/codegen/query_codegen.py:467:26: Attribute `value` on type `NameNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/codegen/query_codegen.py:486:13: Attribute `value` on type `NameNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/codegen/query_codegen.py:636:25: Attribute `value` on type `NameNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/codegen/query_codegen.py:721:13: Attribute `value` on type `NameNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/codegen/query_codegen.py:769:30: Attribute `selections` on type `SelectionSetNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/codegen/query_codegen.py:778:30: Attribute `selections` on type `SelectionSetNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/codegen/query_codegen.py:827:30: Attribute `selections` on type `SelectionSetNode | None` is possibly unbound
- error[lint:unsupported-operator] strawberry/dataloader.py:207:39: Operator `>=` is not supported for types `int` and `None`, in comparing `int` with `Unknown | int | None`
- error[lint:invalid-argument-type] strawberry/dataloader.py:212:61: Argument to this function is incorrect: Expected `Batch[Unknown, Unknown]`, found `Batch[Unknown, Unknown] | None`
- error[lint:invalid-return-type] strawberry/dataloader.py:213:16: Return type does not match returned value: Expected `Batch[Unknown, Unknown]`, found `Batch[Unknown, Unknown] | None`
- warning[lint:redundant-cast] strawberry/django/views.py:86:16: Value is already of type `Unknown`
- warning[lint:redundant-cast] strawberry/django/views.py:117:16: Value is already of type `Unknown`
- warning[lint:possibly-unbound-attribute] strawberry/extensions/max_aliases.py:74:22: Attribute `selections` on type `SelectionSetNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/extensions/query_depth_limiter.py:184:12: Attribute `value` on type `NameNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/extensions/query_depth_limiter.py:261:30: Attribute `selections` on type `SelectionSetNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/federation/schema.py:241:22: Attribute `import_url` on type `ComposeOptions | None` is possibly unbound
- error[lint:not-iterable] strawberry/http/__init__.py:21:52: Object of type `@Todo(specialized non-generic class) | None` may not be iterable
- warning[lint:possibly-unbound-attribute] strawberry/permission.py:173:31: Attribute `of_type` on type `StrawberryType | @Todo(unknown type subscript)` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/printer/printer.py:525:16: Attribute `__strawberry_definition__` on type `type[WithStrawberryObjectDefinition] | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/printer/printer.py:527:9: Attribute `__strawberry_definition__` on type `type[WithStrawberryObjectDefinition] | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/printer/printer.py:549:25: Attribute `__strawberry_definition__` on type `type[WithStrawberryObjectDefinition] | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/printer/printer.py:553:29: Attribute `__strawberry_definition__` on type `type[WithStrawberryObjectDefinition] | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/relay/fields.py:275:25: Attribute `signature` on type `StrawberryResolver[Unknown] | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/relay/fields.py:281:17: Attribute `_namespace` on type `StrawberryResolver[Unknown] | None` is possibly unbound
- error[lint:invalid-argument-type] strawberry/relay/fields.py:295:65: Argument to this function is incorrect: Expected `StrawberryResolver[Unknown]`, found `StrawberryResolver[Unknown] | None`
- warning[lint:possibly-unbound-attribute] strawberry/schema/name_converter.py:68:40: Attribute `is_graphql_generic` on type `StrawberryObjectDefinition | None` is possibly unbound
- error[lint:invalid-return-type] strawberry/schema/name_converter.py:106:20: Return type does not match returned value: Expected `str`, found `Unknown | str | None`
- warning[lint:possibly-unbound-attribute] strawberry/schema/name_converter.py:111:34: Attribute `graphql_name` on type `StrawberryUnion | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/schema/name_converter.py:112:37: Attribute `types` on type `StrawberryUnion | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/schema/name_converter.py:129:34: Attribute `graphql_name` on type `StrawberryUnion | None` is possibly unbound
- error[lint:unsupported-operator] strawberry/schema/name_converter.py:130:13: Operator `+=` is unsupported between objects of type `Literal[""]` and `Unknown | str | None`
- warning[lint:possibly-unbound-attribute] strawberry/schema/name_converter.py:130:21: Attribute `graphql_name` on type `StrawberryUnion | None` is possibly unbound
- error[lint:invalid-return-type] strawberry/schema/name_converter.py:190:20: Return type does not match returned value: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] strawberry/schema/schema.py:129:13: Argument to this function is incorrect: Expected `DocumentNode`, found `DocumentNode | None`
- error[lint:invalid-raise] strawberry/schema/schema.py:284:23: Cannot raise object of type `BaseException | None` (must be a `BaseException` subclass or instance)
- error[lint:invalid-argument-type] strawberry/schema/schema.py:695:33: Argument to this function is incorrect: Expected `DocumentNode`, found `DocumentNode | None`
- warning[lint:possibly-unbound-attribute] strawberry/schema/schema_converter.py:201:28: Attribute `arguments` on type `StrawberryResolver[Unknown] | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/schema/schema_converter.py:222:12: Attribute `self_parameter` on type `StrawberryResolver[Unknown] | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/schema/schema_converter.py:225:32: Attribute `parent_parameter` on type `StrawberryResolver[Unknown] | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/schema/schema_converter.py:228:30: Attribute `root_parameter` on type `StrawberryResolver[Unknown] | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/schema/schema_converter.py:231:30: Attribute `info_parameter` on type `StrawberryResolver[Unknown] | None` is possibly unbound
- error[lint:invalid-return-type] strawberry/schema/schema_converter.py:531:24: Return type does not match returned value: Expected `(Any, GraphQLResolveInfo, Unknown, /) -> @Todo(specialized non-generic class) | str | None`, found `((Any, GraphQLResolveInfo, Unknown, /) -> str) | None`
- warning[lint:possibly-unbound-attribute] strawberry/schema/schema_converter.py:632:24: Attribute `origin` on type `StrawberryObjectDefinition | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/schema/schema_converter.py:920:24: Attribute `origin` on type `StrawberryObjectDefinition | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/schema_codegen/__init__.py:187:19: Attribute `value` on type `StringValueNode | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/schema_codegen/__init__.py:629:19: Attribute `value` on type `StringValueNode | None` is possibly unbound
- error[lint:not-iterable] strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py:405:64: Object of type `@Todo(specialized non-generic class) | None` may not be iterable
- error[lint:not-iterable] strawberry/subscriptions/protocols/graphql_ws/handlers.py:225:42: Object of type `@Todo(specialized non-generic class) | None` may not be iterable
- error[lint:invalid-argument-type] strawberry/types/field.py:377:47: Argument to this function is incorrect: Expected `Mapping[str, StrawberryType | type[WithStrawberryObjectDefinition]]`, found `Mapping[str, StrawberryType | type]`
+ error[lint:invalid-argument-type] strawberry/types/field.py:377:47: Argument to this function is incorrect: Expected `Mapping[str, StrawberryType | type[WithStrawberryObjectDefinition]]`, found `Mapping[str, StrawberryType | type] & ~AlwaysFalsy`
- warning[lint:possibly-unbound-attribute] strawberry/types/lazy_type.py:55:23: Attribute `f_globals` on type `FrameType | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] strawberry/utils/operation.py:31:27: Attribute `value` on type `NameNode | None` is possibly unbound
- Found 451 diagnostics
+ Found 399 diagnostics

comtypes (https://github.com/enthought/comtypes)
- warning[lint:possibly-unbound-attribute] comtypes/_comobject.py:311:13: Attribute `Lock` on type `None | InprocServer | LocalServer` is possibly unbound
- warning[lint:possibly-unbound-attribute] comtypes/_comobject.py:323:13: Attribute `Unlock` on type `None | InprocServer | LocalServer` is possibly unbound
- error[lint:not-iterable] comtypes/_memberspec.py:445:33: Object of type `@Todo(full tuple[...] support) | None` may not be iterable
- error[lint:not-iterable] comtypes/_memberspec.py:453:33: Object of type `@Todo(full tuple[...] support) | None` may not be iterable
- error[lint:not-iterable] comtypes/_memberspec.py:459:33: Object of type `@Todo(full tuple[...] support) | None` may not be iterable
- error[lint:not-iterable] comtypes/_memberspec.py:507:76: Object of type `@Todo(full tuple[...] support) | None` may not be iterable
- warning[lint:possibly-unbound-attribute] comtypes/server/inprocserver.py:43:13: Attribute `Lock` on type `None | InprocServer | LocalServer` is possibly unbound
- warning[lint:possibly-unbound-attribute] comtypes/server/inprocserver.py:45:13: Attribute `Unlock` on type `None | InprocServer | LocalServer` is possibly unbound
- warning[lint:possibly-unbound-attribute] comtypes/server/inprocserver.py:155:14: Attribute `DllCanUnloadNow` on type `None | InprocServer | LocalServer` is possibly unbound
- warning[lint:possibly-unbound-attribute] comtypes/server/localserver.py:94:13: Attribute `Lock` on type `None | InprocServer | LocalServer` is possibly unbound
- warning[lint:possibly-unbound-attribute] comtypes/server/localserver.py:96:13: Attribute `Unlock` on type `None | InprocServer | LocalServer` is possibly unbound
- error[lint:unsupported-operator] comtypes/tools/codegenerator/codegenerator.py:460:16: Operator `//` is unsupported between objects of type `Unknown | int | None` and `Literal[8]`
- warning[lint:possibly-unbound-attribute] comtypes/tools/codegenerator/codegenerator.py:631:23: Attribute `get_head` on type `Unknown | ComInterface | None` is possibly unbound
- error[lint:invalid-argument-type] comtypes/tools/codegenerator/heads.py:85:33: Argument to this function is incorrect: Expected `str`, found `Unknown | str | None`
- error[lint:invalid-argument-type] comtypes/tools/codegenerator/heads.py:104:33: Argument to this function is incorrect: Expected `str`, found `Unknown | str | None`
- error[lint:invalid-argument-type] comtypes/tools/codegenerator/heads.py:141:33: Argument to this function is incorrect: Expected `str`, found `Unknown | str | None`
- error[lint:invalid-argument-type] comtypes/tools/codegenerator/heads.py:182:33: Argument to this function is incorrect: Expected `str`, found `Unknown | str | None`
- Found 678 diagnostics
+ Found 661 diagnostics

ignite (https://github.com/pytorch/ignite)
- error[lint:unsupported-operator] ignite/engine/engine.py:750:57: Operator `>=` is not supported for types `int` and `None`, in comparing `Unknown | Literal[0]` with `int | None`
- error[lint:unsupported-operator] ignite/engine/engine.py:754:36: Operator `*` is unsupported between objects of type `int | None` and `int | None`
- error[lint:unsupported-operator] ignite/engine/engine.py:756:59: Operator `>=` is not supported for types `int` and `None`, in comparing `Unknown | Literal[0]` with `int | None`
- error[lint:unsupported-operator] ignite/handlers/fbresearch_logger.py:157:50: Operator `+` is unsupported between objects of type `Unknown | int | None` and `Literal[1]`
- error[lint:unsupported-operator] ignite/handlers/fbresearch_logger.py:246:40: Operator `>` is not supported for types `None` and `int`, in comparing `Unknown | int | None` with `Literal[1]`
- error[lint:call-non-callable] tests/ignite/metrics/test_precision.py:351:21: Method `__getitem__` of type `Unknown | (Overload[(i: SupportsIndex, /) -> _T, (s: slice[Any, _StartT_co, _StartT_co | _StopT_co], /) -> @Todo(specialized non-generic class)])` is not callable on object of type `Unknown | int | float | list`
- warning[lint:possibly-unresolved-reference] tests/ignite/metrics/test_precision.py:351:21: Name `y_preds` used when possibly not defined
+ warning[lint:unresolved-reference] tests/ignite/metrics/test_precision.py:351:21: Name `y_preds` used when not defined
- warning[lint:call-possibly-unbound-method] tests/ignite/metrics/test_precision.py:352:21: Method `__getitem__` of type `Unknown | int | float | list` is possibly unbound
- warning[lint:possibly-unresolved-reference] tests/ignite/metrics/test_precision.py:352:21: Name `y_true` used when possibly not defined
+ warning[lint:unresolved-reference] tests/ignite/metrics/test_precision.py:352:21: Name `y_true` used when not defined
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:377:17: Attribute `cpu` on type `Unknown | int | float | list` is possibly unbound
- error[lint:call-non-callable] tests/ignite/metrics/test_precision.py:403:21: Method `__getitem__` of type `Unknown | (Overload[(i: SupportsIndex, /) -> _T, (s: slice[Any, _StartT_co, _StartT_co | _StopT_co], /) -> @Todo(specialized non-generic class)])` is not callable on object of type `Unknown | int | float | list`
- warning[lint:possibly-unresolved-reference] tests/ignite/metrics/test_precision.py:403:21: Name `y_preds` used when possibly not defined
+ warning[lint:unresolved-reference] tests/ignite/metrics/test_precision.py:403:21: Name `y_preds` used when not defined
- error[lint:call-non-callable] tests/ignite/metrics/test_precision.py:404:21: Method `__getitem__` of type `Unknown | (Overload[(i: SupportsIndex, /) -> _T, (s: slice[Any, _StartT_co, _StartT_co | _StopT_co], /) -> @Todo(specialized non-generic class)])` is not callable on object of type `Unknown | int | float | list`
- warning[lint:possibly-unresolved-reference] tests/ignite/metrics/test_precision.py:404:21: Name `y_true` used when possibly not defined
+ warning[lint:unresolved-reference] tests/ignite/metrics/test_precision.py:404:21: Name `y_true` used when not defined
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:461:17: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:462:24: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:462:48: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:467:21: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:468:28: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:468:54: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:471:24: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:471:68: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:471:89: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:494:17: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:495:24: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:495:48: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:500:21: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:501:28: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:501:54: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:504:24: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:504:68: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_precision.py:504:89: Attribute `device` on type `int | Unknown` is possibly unbound
- error[lint:call-non-callable] tests/ignite/metrics/test_recall.py:354:21: Method `__getitem__` of type `Unknown | (Overload[(i: SupportsIndex, /) -> _T, (s: slice[Any, _StartT_co, _StartT_co | _StopT_co], /) -> @Todo(specialized non-generic class)])` is not callable on object of type `Unknown | int | float | list`
- warning[lint:possibly-unresolved-reference] tests/ignite/metrics/test_recall.py:354:21: Name `y_preds` used when possibly not defined
+ warning[lint:unresolved-reference] tests/ignite/metrics/test_recall.py:354:21: Name `y_preds` used when not defined
- warning[lint:call-possibly-unbound-method] tests/ignite/metrics/test_recall.py:355:21: Method `__getitem__` of type `Unknown | int | float | list` is possibly unbound
- warning[lint:possibly-unresolved-reference] tests/ignite/metrics/test_recall.py:355:21: Name `y_true` used when possibly not defined
+ warning[lint:unresolved-reference] tests/ignite/metrics/test_recall.py:355:21: Name `y_true` used when not defined
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:380:17: Attribute `cpu` on type `Unknown | int | float | list` is possibly unbound
- error[lint:call-non-callable] tests/ignite/metrics/test_recall.py:406:21: Method `__getitem__` of type `Unknown | (Overload[(i: SupportsIndex, /) -> _T, (s: slice[Any, _StartT_co, _StartT_co | _StopT_co], /) -> @Todo(specialized non-generic class)])` is not callable on object of type `Unknown | int | float | list`
- warning[lint:possibly-unresolved-reference] tests/ignite/metrics/test_recall.py:406:21: Name `y_preds` used when possibly not defined
+ warning[lint:unresolved-reference] tests/ignite/metrics/test_recall.py:406:21: Name `y_preds` used when not defined
- error[lint:call-non-callable] tests/ignite/metrics/test_recall.py:407:21: Method `__getitem__` of type `Unknown | (Overload[(i: SupportsIndex, /) -> _T, (s: slice[Any, _StartT_co, _StartT_co | _StopT_co], /) -> @Todo(specialized non-generic class)])` is not callable on object of type `Unknown | int | float | list`
- warning[lint:possibly-unresolved-reference] tests/ignite/metrics/test_recall.py:407:21: Name `y_true` used when possibly not defined
+ warning[lint:unresolved-reference] tests/ignite/metrics/test_recall.py:407:21: Name `y_true` used when not defined
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:463:17: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:464:24: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:464:48: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:469:21: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:470:28: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:470:54: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:473:24: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:473:68: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:473:89: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:497:17: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:498:24: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:498:48: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:503:21: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:504:28: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:504:54: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:507:24: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:507:68: Attribute `device` on type `int | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] tests/ignite/metrics/test_recall.py:507:89: Attribute `device` on type `int | Unknown` is possibly unbound
- Found 2263 diagnostics
+ Found 2212 diagnostics

check-jsonschema (https://github.com/python-jsonschema/check-jsonschema)
- error[lint:invalid-argument-type] src/check_jsonschema/cli/main_command.py:304:36: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] src/check_jsonschema/cli/main_command.py:308:13: Argument to this function is incorrect: Expected `str`, found `str | None`
- warning[lint:possibly-unbound-attribute] src/check_jsonschema/utils.py:102:18: Attribute `tb_lineno` on type `TracebackType | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/check_jsonschema/utils.py:103:20: Attribute `tb_frame` on type `TracebackType | None` is possibly unbound
- error[lint:not-iterable] src/check_jsonschema/utils.py:140:18: Object of type `@Todo(specialized non-generic class) | None` may not be iterable
- Found 62 diagnostics
+ Found 57 diagnostics

pip (https://github.com/pypa/pip)
- warning[lint:possibly-unbound-attribute] src/pip/_internal/cli/parser.py:55:41: Attribute `lower` on type `str | None` is possibly unbound
- error[lint:invalid-argument-type] src/pip/_internal/cli/req_command.py:67:40: Argument to this function is incorrect: Expected `TempDirectoryTypeRegistry`, found `TempDirectoryTypeRegistry | None`
- error[lint:invalid-argument-type] src/pip/_internal/cli/req_command.py:75:40: Argument to this function is incorrect: Expected `TempDirectoryTypeRegistry`, found `TempDirectoryTypeRegistry | None`
- error[lint:invalid-argument-type] src/pip/_internal/commands/uninstall.py:74:53: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] src/pip/_internal/commands/uninstall.py:90:57: Argument to this function is incorrect: Expected `str`, found `str | None`
- warning[lint:possibly-unbound-attribute] src/pip/_internal/index/package_finder.py:937:33: Attribute `version` on type `BaseDistribution | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/models/installation_report.py:22:30: Attribute `to_dict` on type `DirectUrl | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/models/installation_report.py:29:26: Attribute `is_yanked` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/network/download.py:156:59: Attribute `status_code` on type `Unknown | Response | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/network/utils.py:39:22: Attribute `decode` on type `Unknown | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/network/utils.py:41:22: Attribute `decode` on type `Unknown | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/network/xmlrpc.py:58:17: Attribute `status_code` on type `Unknown | Response | None` is possibly unbound
- error[lint:invalid-argument-type] src/pip/_internal/operations/freeze.py:116:69: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:call-non-callable] src/pip/_internal/operations/freeze.py:120:36: Method `__getitem__` of type `bound method dict[str, @Todo(specialized non-generic class)].__getitem__(key: str, /) -> @Todo(specialized non-generic class)` is not callable on object of type `dict[str, @Todo(specialized non-generic class)]`
- error[lint:call-non-callable] src/pip/_internal/operations/freeze.py:129:33: Method `__getitem__` of type `bound method dict[str, @Todo(specialized non-generic class)].__getitem__(key: str, /) -> @Todo(specialized non-generic class)` is not callable on object of type `dict[str, @Todo(specialized non-generic class)]`
- error[lint:call-non-callable] src/pip/_internal/operations/freeze.py:133:29: Method `__getitem__` of type `bound method dict[str, @Todo(specialized non-generic class)].__getitem__(key: str, /) -> @Todo(specialized non-generic class)` is not callable on object of type `dict[str, @Todo(specialized non-generic class)]`
- error[lint:invalid-argument-type] src/pip/_internal/operations/prepare.py:289:56: Argument to this function is incorrect: Expected `Requirement`, found `Unknown | None | Requirement`
- error[lint:invalid-assignment] src/pip/_internal/operations/prepare.py:295:17: Object of type `Unknown | str | InstallRequirement | None` is not assignable to `str | None`
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:297:30: Attribute `from_path` on type `Unknown | str | InstallRequirement | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:410:13: Attribute `name` on type `Unknown | None | Requirement` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:418:75: Attribute `name` on type `Unknown | None | Requirement` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:420:30: Attribute `name` on type `Unknown | None | Requirement` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:507:50: Attribute `is_wheel` on type `Unknown | Link | None` is possibly unbound
- error[lint:invalid-argument-type] src/pip/_internal/operations/prepare.py:510:21: Argument to this function is incorrect: Expected `Link`, found `Unknown | Link | None`
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:524:34: Attribute `url` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:575:20: Attribute `is_wheel` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:576:20: Attribute `is_file` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:580:28: Attribute `info` on type `DirectUrl | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:581:21: Attribute `info` on type `DirectUrl | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:582:39: Attribute `info` on type `DirectUrl | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:600:12: Attribute `is_existing_dir` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:602:14: Attribute `url` on type `Unknown | Link | None` is possibly unbound
- error[lint:invalid-argument-type] src/pip/_internal/operations/prepare.py:605:21: Argument to this function is incorrect: Expected `Link`, found `Unknown | Link | None`
+ error[lint:unresolved-attribute] src/pip/_internal/operations/prepare.py:634:28: Type `None` has no attribute `info`
+ error[lint:unresolved-attribute] src/pip/_internal/operations/prepare.py:635:25: Type `None` has no attribute `info`
+ error[lint:unresolved-attribute] src/pip/_internal/operations/prepare.py:641:17: Type `None` has no attribute `info`
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:618:42: Attribute `url` on type `Unknown | Link | None` is possibly unbound
- error[lint:invalid-argument-type] src/pip/_internal/operations/prepare.py:628:54: Argument to this function is incorrect: Expected `Link`, found `Unknown | Link | None`
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:634:28: Attribute `info` on type `DirectUrl | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:635:25: Attribute `info` on type `DirectUrl | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:641:17: Attribute `info` on type `DirectUrl | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:661:12: Attribute `is_vcs` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:661:28: Attribute `is_existing_dir` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:666:12: Attribute `is_existing_dir` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:677:61: Attribute `filename` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/operations/prepare.py:728:58: Attribute `version` on type `BaseDistribution | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/req/constructors.py:488:17: Attribute `get` on type `dict[str, Any] | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/req/constructors.py:493:17: Attribute `get` on type `dict[str, Any] | None` is possibly unbound
- error[lint:invalid-argument-type] src/pip/_internal/req/constructors.py:529:37: Argument to this function is incorrect: Expected `Requirement`, found `Unknown | None | Requirement`
- error[lint:invalid-argument-type] src/pip/_internal/req/constructors.py:558:33: Argument to this function is incorrect: Expected `Requirement`, found `Unknown | None | Requirement`
- error[lint:invalid-argument-type] src/pip/_internal/req/req_file.py:210:9: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] src/pip/_internal/req/req_set.py:47:42: Argument to this function is incorrect: Expected `str`, found `str | None`
- warning[lint:possibly-unbound-attribute] src/pip/_internal/resolution/legacy/resolver.py:228:33: Attribute `is_wheel` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/resolution/legacy/resolver.py:229:27: Attribute `filename` on type `Unknown | Link | None` is possibly unbound
- error[lint:invalid-argument-type] src/pip/_internal/resolution/legacy/resolver.py:249:17: Argument to this function is incorrect: Expected `str`, found `str | None`
- warning[lint:possibly-unbound-attribute] src/pip/_internal/resolution/legacy/resolver.py:261:47: Attribute `specifier` on type `Unknown | None | Requirement` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/resolution/legacy/resolver.py:282:35: Attribute `path` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/resolution/legacy/resolver.py:325:38: Attribute `in_usersite` on type `BaseDistribution | None` is possibly unbound
- error[lint:invalid-argument-type] src/pip/_internal/resolution/legacy/resolver.py:438:21: Argument to this function is incorrect: Expected `Link`, found `Unknown | Link | None`
- error[lint:invalid-argument-type] src/pip/_internal/resolution/legacy/resolver.py:537:52: Argument to this function is incorrect: Expected `str`, found `str | None`
- warning[lint:possibly-unbound-attribute] src/pip/_internal/resolution/resolvelib/candidates.py:110:43: Attribute `url` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/resolution/resolvelib/factory.py:485:57: Attribute `specifier` on type `Unknown | None | Requirement` is possibly unbound
- error[lint:invalid-argument-type] src/pip/_internal/resolution/resolvelib/factory.py:497:40: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] src/pip/_internal/resolution/resolvelib/factory.py:509:66: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:unsupported-operator] src/pip/_internal/utils/direct_url_helpers.py:26:26: Operator `+` is unsupported between objects of type `Literal["subdirectory="]` and `str | None`
- error[lint:not-iterable] src/pip/_internal/utils/logging.py:180:34: Object of type `None` is not iterable
- error[lint:no-matching-overload] src/pip/_internal/utils/misc.py:530:12: No overload of bound method `replace` matches arguments
- error[lint:invalid-argument-type] src/pip/_internal/utils/misc.py:530:59: Argument to this function is incorrect: Expected `str`, found `str | None`
- warning[lint:possibly-unbound-attribute] src/pip/_internal/utils/subprocess.py:151:9: Attribute `close` on type `IO[Unknown] | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/utils/subprocess.py:154:25: Attribute `readline` on type `IO[Unknown] | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/utils/subprocess.py:170:17: Attribute `close` on type `IO[Unknown] | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/wheel_builder.py:82:21: Attribute `is_vcs` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/wheel_builder.py:87:50: Attribute `scheme` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/wheel_builder.py:89:50: Attribute `url` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/wheel_builder.py:94:17: Attribute `splitext` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/wheel_builder.py:94:17: Attribute `splitext` on type `Unknown | Link | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_internal/wheel_builder.py:94:17: Attribute `splitext` on type `Unknown | Link | None` is possibly unbound
- error[lint:invalid-argument-type] src/pip/_internal/wheel_builder.py:112:51: Argument to this function is incorrect: Expected `Link`, found `Unknown | Link | None`
- error[lint:invalid-argument-type] src/pip/_internal/wheel_builder.py:114:57: Argument to this function is incorrect: Expected `Link`, found `Unknown | Link | None`
- error[lint:invalid-argument-type] src/pip/_internal/wheel_builder.py:207:21: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] src/pip/_internal/wheel_builder.py:208:21: Argument to this function is incorrect: Expected `BuildBackendHookCaller`, found `BuildBackendHookCaller | None`
- error[lint:invalid-argument-type] src/pip/_internal/wheel_builder.py:209:21: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] src/pip/_internal/wheel_builder.py:214:21: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] src/pip/_internal/wheel_builder.py:215:21: Argument to this function is incorrect: Expected `BuildBackendHookCaller`, found `BuildBackendHookCaller | None`
- error[lint:invalid-argument-type] src/pip/_internal/wheel_builder.py:216:21: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:invalid-argument-type] src/pip/_internal/wheel_builder.py:221:17: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:unsupported-operator] src/pip/_vendor/requests/utils.py:805:17: Operator `+=` is unsupported between objects of type `None` and `str`
- warning[lint:possibly-unbound-attribute] src/pip/_vendor/requests/utils.py:808:20: Attribute `endswith` on type `str | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_vendor/requests/utils.py:808:54: Attribute `endswith` on type `str | None | Unknown` is possibly unbound
- error[lint:invalid-argument-type] src/pip/_vendor/requests/utils.py:816:35: Argument to this function is incorrect: Expected `str`, found `str | None`
- error[lint:unsupported-operator] src/pip/_vendor/requests/utils.py:850:9: Operator `+` is unsupported between objects of type `str` and `str | None`
- error[lint:unsupported-operator] src/pip/_vendor/requests/utils.py:852:9: Operator `+` is unsupported between objects of type `Literal["all://"]` and `str | None`
- warning[lint:possibly-unbound-attribute] src/pip/_vendor/rich/console.py:2358:44: Attribute `is_default` on type `Color | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_vendor/rich/console.py:2359:22: Attribute `get_truecolor` on type `Color | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_vendor/rich/console.py:2363:46: Attribute `is_default` on type `Color | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_vendor/rich/console.py:2364:22: Attribute `get_truecolor` on type `Color | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_vendor/rich/console.py:2466:30: Attribute `get_truecolor` on type `@Todo(map_with_boundness: intersections with negative contributions) | Color | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_vendor/rich/console.py:2474:30: Attribute `get_truecolor` on type `@Todo(map_with_boundness: intersections with negative contributions) | Color | None` is possibly unbound
- error[lint:not-iterable] src/pip/_vendor/rich/logging.py:141:50: Object of type `None` is not iterable
- warning[lint:possibly-unbound-attribute] src/pip/_vendor/rich/markup.py:181:38: Attribute `strip` on type `str | None | Unknown` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_vendor/rich/progress_bar.py:94:13: Attribute `get_truecolor` on type `Color | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_vendor/rich/progress_bar.py:99:13: Attribute `get_truecolor` on type `Color | None` is possibly unbound
- warning[lint:possibly-unbound-attribute] src/pip/_vendor/rich/traceback.py:649:33: Attribute `msg` on type `_SyntaxError | None` is possibly unbound
- error[lint:invalid-argument-type] src/pip/_vendor/rich/traceback.py:737:21: Argument to this function is incorrect: Expected `Mapping[str, Any]`, found `dict[Unknown, Unknown] | None`
+ error[lint:invalid-argument-type] src/pip/_vendor/rich/traceback.py:737:21: Argument to this function is incorrect: Expected `Mapping[str, Any]`, found `dict[Unknown, Unknown] & ~AlwaysFalsy`
- Found 1014 diagnostics
+ Found 917 diagnostics

trio (https://github.com/python-trio/trio)
- warning[lint:possibly-unbound-attribute] src/trio/_core/_run.py:1971:13: Attribute `_child_finished` on type `Nursery | None` is possibly unbound
- error[lint:unresolved-attribute] src/trio/_core/_run.py:2433:29: Type `Outcome[object] | None` has no attribute `value`
- error[lint:unresolved-attribute] src/trio/_core/_run.py:2435:15: Type `Outcome[object] | None` has no attribute `error`
- error[lint:unresolved-attribute] src/trio/_core/_run.py:2700:21: Type `Clock` ...*[Comment body truncated]*

@mtshiba mtshiba force-pushed the attr-subscript-narrowing branch from a9ee6ed to cfa79a2 Compare April 26, 2025 13:35
@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Apr 26, 2025
@sharkdp
Copy link
Contributor

sharkdp commented Apr 29, 2025

Thank you for working on this!

Advanced narrowing mechanisms, such as the following, are not implemented in this PR (and will be future works)

  • narrowing by overwriting assignments

I think it's not just a matter of additional narrowing. It looks to me like, on this branch, we can infer incorrect types by not considering attribute assignments:

from typing import reveal_type

class C:
    x: int | None = None

c = C()

if c.x is None:
    c.x = 1

    reveal_type(c.x)  # this branch: None

I'm afraid this is something that we need to fix before we can consider merging this. It also leads to some new false positives in the ecosystem checks. Please let me know if you need any help with this.

@dhruvmanila
Copy link
Member

(Converting this into draft as I think this requires #18041 ?)

@AlexWaygood AlexWaygood removed their request for review May 20, 2025 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ty Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support narrowing on attribute and subscript expressions
4 participants