Skip to content

[ty] infer function's return type - #17371

Closed
mtshiba wants to merge 131 commits into
astral-sh:mainfrom
mtshiba:infer-return-type
Closed

mtshiba wants to merge 131 commits into
astral-sh:mainfrom
mtshiba:infer-return-type

Conversation

@mtshiba

@mtshiba mtshiba commented Apr 13, 2025 •

Copy link
Copy Markdown
Collaborator

Summary

This PR closes astral-sh/ty#128.

FunctionType::infer_return_type is added to infer the return type of a function when its return type is not specified.

TODOs

  • infer simple function's return type
    - [ ] infer generator's return type
    - [ ] infer coroutine's return type
    - [ ] infer lambda function's return type

Test Plan

New test cases are added to mdtest/function/return_type.md.

@github-actions

github-actions Bot commented Apr 13, 2025 •

Copy link
Copy Markdown
Contributor

mypy_primer results

Changes were detected when running on open source projects
zipp (https://github.com/jaraco/zipp)
+ zipp/__init__.py:373:29: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `str | PathLike[str]`, found `Unknown | str | None`
+ zipp/__init__.py:433:16: error[no-matching-overload] No overload of function `join` matches arguments
+ zipp/glob.py:67:16: error[no-matching-overload] No overload of bound method `join` matches arguments
- Found 4 diagnostics
+ Found 7 diagnostics

attrs (https://github.com/python-attrs/attrs)
+ src/attr/_make.py:453:19: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Self@from_counting_attr | Unknown`
+ src/attr/_make.py:457:19: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Self@from_counting_attr | Unknown`
- src/attr/_make.py:475:35: warning[possibly-missing-attribute] Attribute `init` may be missing on object of type `Attribute | Unknown`
+ src/attr/_make.py:475:35: warning[possibly-missing-attribute] Attribute `init` may be missing on object of type `Unknown | Self@evolve`
- src/attr/_make.py:475:59: warning[possibly-missing-attribute] Attribute `kw_only` may be missing on object of type `Attribute | Unknown`
+ src/attr/_make.py:475:59: warning[possibly-missing-attribute] Attribute `kw_only` may be missing on object of type `Unknown | Self@evolve`
- src/attr/_make.py:480:37: warning[possibly-missing-attribute] Attribute `default` may be missing on object of type `Attribute | Unknown`
+ src/attr/_make.py:480:37: warning[possibly-missing-attribute] Attribute `default` may be missing on object of type `Unknown | Self@evolve`
- src/attr/_make.py:487:16: warning[possibly-missing-attribute] Attribute `alias` may be missing on object of type `Attribute | Unknown`
+ src/attr/_make.py:487:16: warning[possibly-missing-attribute] Attribute `alias` may be missing on object of type `Unknown | Self@evolve`
- src/attr/_make.py:489:70: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Attribute | Unknown`
+ src/attr/_make.py:489:70: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Unknown | Self@evolve`
- src/attr/_make.py:493:19: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Attribute | Unknown`
+ src/attr/_make.py:493:19: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Unknown | Self@evolve`
- src/attr/_make.py:797:13: error[invalid-assignment] Object of type `ReferenceType[Unknown]` is not assignable to attribute `__attrs_base_of_slotted__` on type `Unknown | type`
+ src/attr/_make.py:797:13: error[invalid-assignment] Object of type `ReferenceType[Unknown | type]` is not assignable to attribute `__attrs_base_of_slotted__` on type `Unknown | type`
+ src/attr/_make.py:809:13: warning[possibly-missing-attribute] Attribute `__attrs_init_subclass__` may be missing on object of type `Unknown | type`
- src/attr/_make.py:1061:13: error[invalid-argument-type] Argument to function `_make_hash_script` is incorrect: Expected `list[Attribute | Unknown]`, found `Unknown | type`
+ src/attr/_make.py:1061:13: error[invalid-argument-type] Argument to function `_make_hash_script` is incorrect: Expected `list[Attribute]`, found `Unknown | type`
- src/attr/_make.py:1608:13: error[invalid-assignment] Object of type `tuple[Attribute | Unknown, ...]` is not assignable to `list[Attribute | Unknown]`
+ src/attr/_make.py:1608:13: error[invalid-assignment] Object of type `tuple[Attribute, ...]` is not assignable to `list[Attribute]`
- src/attr/_make.py:1609:29: warning[possibly-missing-attribute] Attribute `hash` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:1609:48: warning[possibly-missing-attribute] Attribute `hash` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:1609:67: warning[possibly-missing-attribute] Attribute `eq` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:1647:16: warning[possibly-missing-attribute] Attribute `eq_key` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:1648:32: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:1649:35: warning[possibly-missing-attribute] Attribute `eq_key` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:1651:57: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:1654:62: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2189:12: warning[possibly-missing-attribute] Attribute `validator` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2192:21: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2193:26: warning[possibly-missing-attribute] Attribute `on_setattr` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2194:13: warning[possibly-missing-attribute] Attribute `on_setattr` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2198:20: warning[possibly-missing-attribute] Attribute `alias` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2200:34: warning[possibly-missing-attribute] Attribute `default` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2201:48: warning[possibly-missing-attribute] Attribute `default` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2203:12: warning[possibly-missing-attribute] Attribute `converter` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2203:55: warning[possibly-missing-attribute] Attribute `converter` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2204:35: warning[possibly-missing-attribute] Attribute `converter` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2206:25: warning[possibly-missing-attribute] Attribute `converter` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2208:12: warning[possibly-missing-attribute] Attribute `init` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2210:58: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2220:66: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2231:56: warning[possibly-missing-attribute] Attribute `default` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2241:62: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2252:14: warning[possibly-missing-attribute] Attribute `default` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2254:16: warning[possibly-missing-attribute] Attribute `kw_only` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2266:62: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2274:16: warning[possibly-missing-attribute] Attribute `kw_only` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2281:54: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2299:62: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2315:52: warning[possibly-missing-attribute] Attribute `default` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2317:16: warning[possibly-missing-attribute] Attribute `kw_only` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2329:62: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2335:12: warning[possibly-missing-attribute] Attribute `init` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2336:16: warning[possibly-missing-attribute] Attribute `type` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2337:41: warning[possibly-missing-attribute] Attribute `type` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2373:33: warning[possibly-missing-attribute] Attribute `name` may be missing on object of type `Attribute | Unknown`
- src/attr/_make.py:2373:60: warning[possibly-missing-attribute] Attribute `init` may be missing on object of type `Attribute | Unknown`
+ src/attr/_make.py:1609:29: error[unresolved-attribute] Object of type `Attribute` has no attribute `hash`
+ src/attr/_make.py:1609:48: error[unresolved-attribute] Object of type `Attribute` has no attribute `hash`
+ src/attr/_make.py:1609:67: error[unresolved-attribute] Object of type `Attribute` has no attribute `eq`
+ src/attr/_make.py:1647:16: error[unresolved-attribute] Object of type `Attribute` has no attribute `eq_key`
+ src/attr/_make.py:1648:32: error[unresolved-attribute] Object of type `Attribute` has no attribute `name`
+ src/attr/_make.py:1649:35: error[unresolved-attribute] Object of type `Attribute` has no attribute `eq_key`
+ src/attr/_make.py:1651:57: error[unresolved-attribute] Object of type `Attribute` has no attribute `name`
+ src/attr/_make.py:1654:62: error[unresolved-attribute] Object of type `Attribute` has no attribute `name`
+ src/attr/_make.py:2189:12: error[unresolved-attribute] Object of type `Attribute` has no attribute `validator`
+ src/attr/_make.py:2192:21: error[unresolved-attribute] Object of type `Attribute` has no attribute `name`
+ src/attr/_make.py:2193:26: error[unresolved-attribute] Object of type `Attribute` has no attribute `on_setattr`
+ src/attr/_make.py:2194:13: error[unresolved-attribute] Object of type `Attribute` has no attribute `on_setattr`
+ src/attr/_make.py:2198:20: error[unresolved-attribute] Object of type `Attribute` has no attribute `alias`
+ src/attr/_make.py:2200:34: error[unresolved-attribute] Object of type `Attribute` has no attribute `default`
+ src/attr/_make.py:2201:48: error[unresolved-attribute] Object of type `Attribute` has no attribute `default`
+ src/attr/_make.py:2203:12: error[unresolved-attribute] Object of type `Attribute` has no attribute `converter`
+ src/attr/_make.py:2203:55: error[unresolved-attribute] Object of type `Attribute` has no attribute `converter`
+ src/attr/_make.py:2204:35: error[unresolved-attribute] Object of type `Attribute` has no attribute `converter`
+ src/attr/_make.py:2206:25: error[unresolved-attribute] Object of type `Attribute` has no attribute `converter`
+ src/attr/_make.py:2208:12: error[unresolved-attribute] Object of type `Attribute` has no attribute `init`
+ src/attr/_make.py:2210:58: error[unresolved-attribute] Object of type `Attribute` has no attribute `name`
+ src/attr/_make.py:2220:66: error[unresolved-attribute] Object of type `Attribute` has no attribute `name`
+ src/attr/_make.py:2231:56: error[unresolved-attribute] Object of type `Attribute` has no attribute `default`
+ src/attr/_make.py:2241:62: error[unresolved-attribute] Object of type `Attribute` has no attribute `name`
+ src/attr/_make.py:2252:14: error[unresolved-attribute] Object of type `Attribute` has no attribute `default`
+ src/attr/_make.py:2254:16: error[unresolved-attribute] Object of type `Attribute` has no attribute `kw_only`
+ src/attr/_make.py:2266:62: error[unresolved-attribute] Object of type `Attribute` has no attribute `name`
+ src/attr/_make.py:2274:16: error[unresolved-attribute] Object of type `Attribute` has no attribute `kw_only`
+ src/attr/_make.py:2281:54: error[unresolved-attribute] Object of type `Attribute` has no attribute `name`
+ src/attr/_make.py:2299:62: error[unresolved-attribute] Object of type `Attribute` has no attribute `name`
+ src/attr/_make.py:2315:52: error[unresolved-attribute] Object of type `Attribute` has no attribute `default`
+ src/attr/_make.py:2317:16: error[unresolved-attribute] Object of type `Attribute` has no attribute `kw_only`
+ src/attr/_make.py:2329:62: error[unresolved-attribute] Object of type `Attribute` has no attribute `name`
+ src/attr/_make.py:2335:12: error[unresolved-attribute] Object of type `Attribute` has no attribute `init`
+ src/attr/_make.py:2336:16: error[unresolved-attribute] Object of type `Attribute` has no attribute `type`
+ src/attr/_make.py:2337:41: error[unresolved-attribute] Object of type `Attribute` has no attribute `type`
+ src/attr/_make.py:2373:33: error[unresolved-attribute] Object of type `Attribute` has no attribute `name`
+ src/attr/_make.py:2373:60: error[unresolved-attribute] Object of type `Attribute` has no attribute `init`
+ src/attr/_make.py:2641:13: error[invalid-assignment] Object of type `type` is not assignable to `<class 'Attribute'>`
+ src/attr/_make.py:3038:11: error[invalid-assignment] Object of type `type` is not assignable to `<class 'Factory'>`
+ src/attr/_make.py:3157:13: error[invalid-assignment] Object of type `type` is not assignable to `<class 'Converter'>`
+ src/attr/_make.py:3278:18: error[not-iterable] Object of type `Unknown | _CountingAttr` may not be iterable
+ src/attr/_version_info.py:86:16: error[unsupported-operator] Operator `<` is not supported between objects of type `list[Unknown] | @Todo | tuple[Unknown, ...]` and `Unknown | tuple[Unknown, ...]`
+ src/attr/validators.py:98:34: error[invalid-argument-type] Argument to function `isinstance` is incorrect: Expected `type | tuple[Divergent, ...]`, found `Unknown | _CountingAttr`
+ src/attr/validators.py:137:16: error[call-non-callable] Object of type `_CountingAttr` is not callable
+ src/attr/validators.py:138:53: warning[possibly-missing-attribute] Attribute `pattern` may be missing on object of type `Unknown | _CountingAttr`
+ src/attr/validators.py:206:9: error[call-non-callable] Object of type `_CountingAttr` is not callable
+ src/attr/validators.py:240:26: error[unsupported-operator] Operator `in` is not supported between objects of type `Unknown` and `Unknown | _CountingAttr`
+ src/attr/validators.py:342:13: error[call-non-callable] Object of type `_CountingAttr` is not callable
+ src/attr/validators.py:345:13: error[call-non-callable] Object of type `_CountingAttr` is not callable
+ src/attr/validators.py:396:13: error[call-non-callable] Object of type `_CountingAttr` is not callable
+ src/attr/validators.py:400:17: error[call-non-callable] Object of type `_CountingAttr` is not callable
+ src/attr/validators.py:402:17: error[call-non-callable] Object of type `_CountingAttr` is not callable
+ src/attr/validators.py:468:16: error[call-non-callable] Object of type `_CountingAttr` is not callable
+ src/attr/validators.py:544:12: error[unsupported-operator] Operator `>` is not supported between objects of type `int` and `Unknown | _CountingAttr`
+ src/attr/validators.py:573:12: error[unsupported-operator] Operator `<` is not supported between objects of type `int` and `Unknown | _CountingAttr`
+ src/attr/validators.py:602:34: error[invalid-argument-type] Argument to function `issubclass` is incorrect: Expected `type | tuple[Divergent, ...]`, found `Unknown | _CountingAttr`
+ src/attr/validators.py:650:13: error[call-non-callable] Object of type `_CountingAttr` is not callable
+ src/attr/validators.py:651:16: error[invalid-exception-caught] Invalid object caught in an exception handler: Object has type `Unknown | _CountingAttr`
+ src/attr/validators.py:655:17: warning[possibly-missing-attribute] Attribute `format` may be missing on object of type `Unknown | _CountingAttr`
+ src/attr/validators.py:710:18: error[not-iterable] Object of type `Unknown | _CountingAttr` may not be iterable
+ tests/test_make.py:1365:16: warning[possibly-missing-attribute] Attribute `__attrs_attrs__` may be missing on object of type `Unknown | type`
+ tests/test_make.py:1380:16: warning[possibly-missing-attribute] Attribute `__attrs_attrs__` may be missing on object of type `Unknown | type`
+ tests/test_make.py:1468:30: warning[possibly-missing-attribute] Attribute `echo` may be missing on object of type `Unknown | type`
+ tests/test_make.py:1487:25: warning[possibly-missing-attribute] Attribute `__attrs_attrs__` may be missing on object of type `Unknown | type`
+ tests/test_make.py:3051:30: warning[possibly-missing-attribute] Attribute `__match_args__` may be missing on object of type `Unknown | type`
+ tests/test_make.py:3057:22: warning[possibly-missing-attribute] Attribute `__match_args__` may be missing on object of type `Unknown | type`
+ tests/test_make.py:3060:26: warning[possibly-missing-attribute] Attribute `__match_args__` may be missing on object of type `Unknown | type`
- Found 616 diagnostics
+ Found 649 diagnostics

parso (https://github.com/davidhalter/parso)
+ parso/__init__.py:58:26: error[invalid-argument-type] Argument to bound method `parse` is incorrect: Expected `str | bytes`, found `Unknown | None`
- parso/grammar.py:163:27: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
+ parso/grammar.py:199:16: warning[possibly-missing-attribute] Attribute `walk` may be missing on object of type `Unknown | None | Normalizer`
+ parso/grammar.py:203:9: warning[possibly-missing-attribute] Attribute `walk` may be missing on object of type `Unknown | None | Normalizer`
+ parso/grammar.py:204:16: warning[possibly-missing-attribute] Attribute `issues` may be missing on object of type `Unknown | None | Normalizer`
+ parso/pgen2/grammar_parser.py:106:20: error[not-iterable] Object of type `None` is not iterable
+ parso/python/diff.py:423:17: error[not-subscriptable] Cannot subscript object of type `None` with no `__getitem__` method
+ parso/python/diff.py:621:16: warning[possibly-missing-attribute] Attribute `tree_node` may be missing on object of type `Unknown | None`
+ parso/python/diff.py:622:9: warning[possibly-missing-attribute] Attribute `add_tree_nodes` may be missing on object of type `Unknown | None`
+ parso/python/errors.py:783:12: warning[possibly-missing-attribute] Attribute `type` may be missing on object of type `Unknown | None`
+ parso/python/errors.py:784:26: warning[possibly-missing-attribute] Attribute `type` may be missing on object of type `Unknown | None`
+ parso/python/errors.py:784:54: warning[possibly-missing-attribute] Attribute `children` may be missing on object of type `Unknown | None`
+ parso/python/errors.py:1166:20: warning[possibly-missing-attribute] Attribute `type` may be missing on object of type `Unknown | None`
+ parso/python/errors.py:1167:34: warning[possibly-missing-attribute] Attribute `type` may be missing on object of type `Unknown | None`
+ parso/python/errors.py:1167:62: warning[possibly-missing-attribute] Attribute `children` may be missing on object of type `Unknown | None`
- parso/python/pep8.py:362:17: warning[possibly-missing-attribute] Attribute `type` may be missing on object of type `Unknown | IndentationNode | None`
+ parso/python/pep8.py:362:17: warning[possibly-missing-attribute] Attribute `type` may be missing on object of type `Unknown | None | IndentationNode`
- parso/python/pep8.py:363:37: warning[possibly-missing-attribute] Attribute `parent` may be missing on object of type `Unknown | IndentationNode | None`
+ parso/python/pep8.py:363:37: warning[possibly-missing-attribute] Attribute `parent` may be missing on object of type `Unknown | None | IndentationNode`
- parso/python/tokenize.py:109:9: error[invalid-assignment] Invalid subscript assignment with key of type `tuple[Unknown, ...]` and value of type `Unknown` on object of type `dict[PythonVersionInfo, TokenCollection]`
+ parso/python/tokenize.py:109:9: error[invalid-assignment] Invalid subscript assignment with key of type `tuple[Unknown, ...]` and value of type `TokenCollection` on object of type `dict[PythonVersionInfo, TokenCollection]`
+ parso/python/tokenize.py:588:31: error[invalid-assignment] Object of type `Pattern[Unknown] | None` is not assignable to `Pattern[Unknown]`
+ parso/python/tree.py:135:21: warning[possibly-missing-attribute] Attribute `token_type` may be missing on object of type `(Unknown & ~None) | NodeOrLeaf`
+ parso/python/tree.py:1129:20: warning[possibly-missing-attribute] Attribute `children` may be missing on object of type `Unknown | NodeOrLeaf`
+ parso/python/tree.py:1130:24: warning[possibly-missing-attribute] Attribute `children` may be missing on object of type `Unknown | NodeOrLeaf`
+ parso/python/tree.py:1131:26: warning[possibly-missing-attribute] Attribute `children` may be missing on object of type `Unknown | NodeOrLeaf`
+ parso/python/tree.py:1149:20: warning[possibly-missing-attribute] Attribute `children` may be missing on object of type `Unknown | NodeOrLeaf`
+ parso/tree.py:447:16: warning[possibly-missing-attribute] Attribute `replace` may be missing on object of type `Unknown | None`
- Found 199 diagnostics
+ Found 219 diagnostics

kornia (https://github.com/kornia/kornia)
+ kornia/feature/dedode/transformer/dinov2.py:317:30: error[invalid-argument-type] Method `__getitem__` of type `Overload[(i: SupportsIndex, /) -> Unknown, (s: slice[Any, Any, Any], /) -> list[Unknown]]` cannot be called with key of type `Literal["x_norm_clstoken"]` on object of type `list[Unknown]`
- Found 758 diagnostics
+ Found 759 diagnostics

pip (https://github.com/pypa/pip)
+ src/pip/_internal/cli/cmdoptions.py:123:51: error[invalid-argument-type] Argument to function `get_file_content` is incorrect: Expected `PipSession`, found `Self@__enter__ | Unknown`
+ src/pip/_internal/commands/index.py:119:17: error[invalid-argument-type] Argument to bound method `_build_package_finder` is incorrect: Expected `PipSession`, found `Self@__enter__ | Unknown`
+ src/pip/_internal/commands/list.py:245:58: error[invalid-argument-type] Argument to bound method `_build_package_finder` is incorrect: Expected `PipSession`, found `Self@__enter__ | Unknown`
+ src/pip/_internal/index/collector.py:311:9: error[invalid-argument-type] Argument is incorrect: Expected `bytes`, found `(Unknown & ~Literal[False]) | None | (bytes & ~AlwaysFalsy) | Literal[b""]`
- src/pip/_vendor/cachecontrol/adapter.py:162:39: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
- src/pip/_vendor/cachecontrol/serialize.py:35:46: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
+ src/pip/_vendor/cachecontrol/serialize.py:36:45: error[invalid-argument-type] Argument to function `len` is incorrect: Expected `Sized`, found `None | bytes | Unknown`
+ src/pip/_vendor/cachecontrol/serialize.py:146:47: error[invalid-argument-type] Argument to bound method `prepare_response` is incorrect: Expected `Mapping[str, Any]`, found `int | Unknown | None | ... omitted 9 union elements`
+ src/pip/_vendor/distlib/compat.py:1127:22: error[call-non-callable] Object of type `ModuleType` is not callable
+ src/pip/_vendor/distlib/resources.py:196:33: error[not-iterable] Object of type `Unknown | Self@__get__` may not be iterable
+ src/pip/_vendor/distlib/resources.py:196:33: warning[possibly-missing-attribute] Attribute `resources` may be missing on object of type `Unknown | ResourceContainer | Resource`
+ src/pip/_vendor/distlib/resources.py:202:28: warning[possibly-missing-attribute] Attribute `is_container` may be missing on object of type `None | ResourceContainer | Resource | Unknown`
+ src/pip/_vendor/msgpack/fallback.py:540:29: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | Buffer`, found `None | Unknown | int | bytearray`
+ src/pip/_vendor/msgpack/fallback.py:542:23: warning[possibly-missing-attribute] Attribute `decode` may be missing on object of type `None | Unknown | int | bytearray`
+ src/pip/_vendor/msgpack/fallback.py:545:26: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | Buffer`, found `None | Unknown | int | bytearray`
+ src/pip/_vendor/msgpack/fallback.py:548:49: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | Buffer`, found `None | Unknown | int | bytearray`
+ src/pip/_vendor/msgpack/fallback.py:558:48: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | Buffer`, found `None | Unknown | int | bytearray`
+ src/pip/_vendor/pkg_resources/__init__.py:2308:28: error[invalid-argument-type] Argument to function `distributions_from_metadata` is incorrect: Expected `str`, found `str | bytes`
+ src/pip/_vendor/pkg_resources/__init__.py:2308:28: error[invalid-argument-type] Argument to function `find_distributions` is incorrect: Expected `str`, found `str | bytes`
+ src/pip/_vendor/pkg_resources/__init__.py:2828:13: error[invalid-assignment] Invalid subscript assignment with key of type `Unknown | str` and value of type `Self@parse | Unknown` on object of type `dict[str, Self@parse_group]`
+ src/pip/_vendor/pkg_resources/__init__.py:2852:13: error[invalid-assignment] Invalid subscript assignment with key of type `str` and value of type `dict[str, Self@parse_group] | Unknown` on object of type `dict[str, dict[str, Self@parse_map]]`
+ src/pip/_vendor/pkg_resources/__init__.py:2941:16: error[unsupported-operator] Operator `<` is not supported between two objects of type `tuple[Unknown | Version, Unknown | int, Unknown | str, Unknown | str | None, (Unknown & ~AlwaysFalsy) | (str & ~AlwaysFalsy) | Literal[""], (Unknown & ~AlwaysFalsy) | (str & ~AlwaysFalsy) | Literal[""]]`
+ src/pip/_vendor/pkg_resources/__init__.py:2944:16: error[unsupported-operator] Operator `<=` is not supported between two objects of type `tuple[Unknown | Version, Unknown | int, Unknown | str, Unknown | str | None, (Unknown & ~AlwaysFalsy) | (str & ~AlwaysFalsy) | Literal[""], (Unknown & ~AlwaysFalsy) | (str & ~AlwaysFalsy) | Literal[""]]`
+ src/pip/_vendor/pkg_resources/__init__.py:2947:16: error[unsupported-operator] Operator `>` is not supported between two objects of type `tuple[Unknown | Version, Unknown | int, Unknown | str, Unknown | str | None, (Unknown & ~AlwaysFalsy) | (str & ~AlwaysFalsy) | Literal[""], (Unknown & ~AlwaysFalsy) | (str & ~AlwaysFalsy) | Literal[""]]`
+ src/pip/_vendor/pkg_resources/__init__.py:2950:16: error[unsupported-operator] Operator `>=` is not supported between two objects of type `tuple[Unknown | Version, Unknown | int, Unknown | str, Unknown | str | None, (Unknown & ~AlwaysFalsy) | (str & ~AlwaysFalsy) | Literal[""], (Unknown & ~AlwaysFalsy) | (str & ~AlwaysFalsy) | Literal[""]]`
- src/pip/_vendor/pkg_resources/__init__.py:3466:40: error[invalid-argument-type] Argument to bound method `contains` is incorrect: Expected `Version | str`, found `(str & ~Distribution) | (tuple[str, ...] & ~Distribution) | Unknown`
+ src/pip/_vendor/pkg_resources/__init__.py:3466:40: error[invalid-argument-type] Argument to bound method `contains` is incorrect: Expected `Version | str`, found `str | (tuple[str, ...] & ~Distribution) | Unknown`
+ src/pip/_vendor/pygments/lexers/python.py:362:42: error[invalid-argument-type] Argument to function `fstring_rules` is incorrect: Expected `PythonLexer`, found `Any | _TokenType`
+ src/pip/_vendor/pygments/lexers/python.py:363:42: error[invalid-argument-type] Argument to function `fstring_rules` is incorrect: Expected `PythonLexer`, found `Any | _TokenType`
+ src/pip/_vendor/pygments/lexers/python.py:364:45: error[invalid-argument-type] Argument to function `innerstring_rules` is incorrect: Expected `PythonLexer`, found `Any | _TokenType`
+ src/pip/_vendor/pygments/lexers/python.py:365:45: error[invalid-argument-type] Argument to function `innerstring_rules` is incorrect: Expected `PythonLexer`, found `Any | _TokenType`
+ src/pip/_vendor/pygments/lexers/python.py:611:45: error[invalid-argument-type] Argument to function `innerstring_rules` is incorrect: Expected `Python2Lexer`, found `Any | _TokenType`
+ src/pip/_vendor/pygments/lexers/python.py:612:45: error[invalid-argument-type] Argument to function `innerstring_rules` is incorrect: Expected `Python2Lexer`, found `Any | _TokenType`
+ src/pip/_vendor/pygments/sphinxext.py:108:26: warning[possibly-missing-attribute] Attribute `filenames` may be missing on object of type `Unknown | None`
+ src/pip/_vendor/pygments/sphinxext.py:108:48: warning[possibly-missing-attribute] Attribute `alias_filenames` may be missing on object of type `Unknown | None`
+ src/pip/_vendor/pygments/sphinxext.py:111:46: warning[possibly-missing-attribute] Attribute `url` may be missing on object of type `Unknown | None`
+ src/pip/_vendor/requests/models.py:121:26: error[not-iterable] Object of type `None | list[Unknown]` may not be iterable
+ src/pip/_vendor/requests/models.py:155:27: error[not-iterable] Object of type `None | list[Unknown]` may not be iterable
+ src/pip/_vendor/requests/models.py:173:21: error[not-iterable] Object of type `None | list[Unknown]` may not be iterable
+ src/pip/_vendor/requests/models.py:602:17: error[call-non-callable] Object of type `tuple[str, str]` is not callable
- src/pip/_vendor/requests/models.py:935:41: error[invalid-argument-type] Argument to class `str` is incorrect: Expected `str`, found `Unknown | None`
+ src/pip/_vendor/requests/models.py:935:41: error[invalid-argument-type] Argument to class `str` is incorrect: Expected `str`, found `Unknown | None | Literal["utf-8"]`
+ src/pip/_vendor/requests/sessions.py:80:5: error[no-matching-overload] No overload of bound method `update` matches arguments
+ src/pip/_vendor/requests/utils.py:615:31: error[invalid-argument-type] Argument to class `str` is incorrect: Expected `str`, found `None | Unknown | Literal["ISO-8859-1", "utf-8"]`
+ src/pip/_vendor/rich/syntax.py:167:27: error[unsupported-operator] Operator `+` is not supported between objects of type `Literal["#"]` and `(Unknown & ~AlwaysFalsy) | (str & ~AlwaysFalsy) | Literal[True]`
+ src/pip/_vendor/rich/syntax.py:168:29: error[unsupported-operator] Operator `+` is not supported between objects of type `Literal["#"]` and `(Unknown & ~AlwaysFalsy) | (str & ~AlwaysFalsy) | Literal[True]`
+ src/pip/_vendor/rich/syntax.py:169:21: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `bool | None`, found `Unknown | str | None | bool`
+ src/pip/_vendor/rich/syntax.py:170:21: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `bool | None`, found `Unknown | str | None | bool`
+ src/pip/_vendor/rich/syntax.py:171:21: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `bool | None`, found `Unknown | str | None | bool`
- src/pip/_vendor/urllib3/connectionpool.py:785:21: warning[possibly-missing-attribute] Attribute `proxy` may be missing on object of type `None | Unknown`
+ src/pip/_vendor/urllib3/connectionpool.py:785:21: warning[possibly-missing-attribute] Attribute `proxy` may be missing on object of type `None | Unknown | HTTPConnection`
- src/pip/_vendor/urllib3/connectionpool.py:786:21: warning[possibly-missing-attribute] Attribute `proxy` may be missing on object of type `None | Unknown`
+ src/pip/_vendor/urllib3/connectionpool.py:786:21: warning[possibly-missing-attribute] Attribute `proxy` may be missing on object of type `None | Unknown | HTTPConnection`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:136:5: warning[possibly-missing-attribute] Attribute `SecItemImport` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:146:5: warning[possibly-missing-attribute] Attribute `SecItemImport` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:148:5: warning[possibly-missing-attribute] Attribute `SecCertificateGetTypeID` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:149:5: warning[possibly-missing-attribute] Attribute `SecCertificateGetTypeID` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:151:5: warning[possibly-missing-attribute] Attribute `SecIdentityGetTypeID` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:152:5: warning[possibly-missing-attribute] Attribute `SecIdentityGetTypeID` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:154:5: warning[possibly-missing-attribute] Attribute `SecKeyGetTypeID` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:155:5: warning[possibly-missing-attribute] Attribute `SecKeyGetTypeID` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:157:5: warning[possibly-missing-attribute] Attribute `SecCertificateCreateWithData` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:158:5: warning[possibly-missing-attribute] Attribute `SecCertificateCreateWithData` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:160:5: warning[possibly-missing-attribute] Attribute `SecCertificateCopyData` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:161:5: warning[possibly-missing-attribute] Attribute `SecCertificateCopyData` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:163:5: warning[possibly-missing-attribute] Attribute `SecCopyErrorMessageString` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:164:5: warning[possibly-missing-attribute] Attribute `SecCopyErrorMessageString` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:166:5: warning[possibly-missing-attribute] Attribute `SecIdentityCreateWithCertificate` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:171:5: warning[possibly-missing-attribute] Attribute `SecIdentityCreateWithCertificate` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:173:5: warning[possibly-missing-attribute] Attribute `SecKeychainCreate` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:181:5: warning[possibly-missing-attribute] Attribute `SecKeychainCreate` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:183:5: warning[possibly-missing-attribute] Attribute `SecKeychainDelete` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:184:5: warning[possibly-missing-attribute] Attribute `SecKeychainDelete` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:186:5: warning[possibly-missing-attribute] Attribute `SecPKCS12Import` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:191:5: warning[possibly-missing-attribute] Attribute `SecPKCS12Import` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:198:5: warning[possibly-missing-attribute] Attribute `SSLSetIOFuncs` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:199:5: warning[possibly-missing-attribute] Attribute `SSLSetIOFuncs` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:201:5: warning[possibly-missing-attribute] Attribute `SSLSetPeerID` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:202:5: warning[possibly-missing-attribute] Attribute `SSLSetPeerID` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:204:5: warning[possibly-missing-attribute] Attribute `SSLSetCertificate` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:205:5: warning[possibly-missing-attribute] Attribute `SSLSetCertificate` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:207:5: warning[possibly-missing-attribute] Attribute `SSLSetCertificateAuthorities` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:208:5: warning[possibly-missing-attribute] Attribute `SSLSetCertificateAuthorities` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:210:5: warning[possibly-missing-attribute] Attribute `SSLSetConnection` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:211:5: warning[possibly-missing-attribute] Attribute `SSLSetConnection` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:213:5: warning[possibly-missing-attribute] Attribute `SSLSetPeerDomainName` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:214:5: warning[possibly-missing-attribute] Attribute `SSLSetPeerDomainName` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:216:5: warning[possibly-missing-attribute] Attribute `SSLHandshake` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:217:5: warning[possibly-missing-attribute] Attribute `SSLHandshake` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:219:5: warning[possibly-missing-attribute] Attribute `SSLRead` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:220:5: warning[possibly-missing-attribute] Attribute `SSLRead` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:222:5: warning[possibly-missing-attribute] Attribute `SSLWrite` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:223:5: warning[possibly-missing-attribute] Attribute `SSLWrite` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:225:5: warning[possibly-missing-attribute] Attribute `SSLClose` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:226:5: warning[possibly-missing-attribute] Attribute `SSLClose` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:228:5: warning[possibly-missing-attribute] Attribute `SSLGetNumberSupportedCiphers` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:229:5: warning[possibly-missing-attribute] Attribute `SSLGetNumberSupportedCiphers` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:231:5: warning[possibly-missing-attribute] Attribute `SSLGetSupportedCiphers` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:236:5: warning[possibly-missing-attribute] Attribute `SSLGetSupportedCiphers` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:238:5: warning[possibly-missing-attribute] Attribute `SSLSetEnabledCiphers` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:243:5: warning[possibly-missing-attribute] Attribute `SSLSetEnabledCiphers` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:245:5: error[unresolved-attribute] Unresolved attribute `argtype` on type `_NamedFuncPointer`.
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:245:5: warning[possibly-missing-attribute] Attribute `SSLGetNumberEnabledCiphers` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:246:5: warning[possibly-missing-attribute] Attribute `SSLGetNumberEnabledCiphers` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:248:5: warning[possibly-missing-attribute] Attribute `SSLGetEnabledCiphers` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:253:5: warning[possibly-missing-attribute] Attribute `SSLGetEnabledCiphers` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:255:5: warning[possibly-missing-attribute] Attribute `SSLGetNegotiatedCipher` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:256:5: warning[possibly-missing-attribute] Attribute `SSLGetNegotiatedCipher` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:258:5: warning[possibly-missing-attribute] Attribute `SSLGetNegotiatedProtocolVersion` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:262:5: warning[possibly-missing-attribute] Attribute `SSLGetNegotiatedProtocolVersion` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:264:5: warning[possibly-missing-attribute] Attribute `SSLCopyPeerTrust` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:265:5: warning[possibly-missing-attribute] Attribute `SSLCopyPeerTrust` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:267:5: warning[possibly-missing-attribute] Attribute `SecTrustSetAnchorCertificates` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:268:5: warning[possibly-missing-attribute] Attribute `SecTrustSetAnchorCertificates` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:270:5: error[unresolved-attribute] Unresolved attribute `argstypes` on type `_NamedFuncPointer`.
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:270:5: warning[possibly-missing-attribute] Attribute `SecTrustSetAnchorCertificatesOnly` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:271:5: warning[possibly-missing-attribute] Attribute `SecTrustSetAnchorCertificatesOnly` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:273:5: warning[possibly-missing-attribute] Attribute `SecTrustEvaluate` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:274:5: warning[possibly-missing-attribute] Attribute `SecTrustEvaluate` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:276:5: warning[possibly-missing-attribute] Attribute `SecTrustGetCertificateCount` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:277:5: warning[possibly-missing-attribute] Attribute `SecTrustGetCertificateCount` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:279:5: warning[possibly-missing-attribute] Attribute `SecTrustGetCertificateAtIndex` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:280:5: warning[possibly-missing-attribute] Attribute `SecTrustGetCertificateAtIndex` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:282:5: warning[possibly-missing-attribute] Attribute `SSLCreateContext` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:287:5: warning[possibly-missing-attribute] Attribute `SSLCreateContext` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:289:5: warning[possibly-missing-attribute] Attribute `SSLSetSessionOption` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:290:5: warning[possibly-missing-attribute] Attribute `SSLSetSessionOption` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:292:5: warning[possibly-missing-attribute] Attribute `SSLSetProtocolVersionMin` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:293:5: warning[possibly-missing-attribute] Attribute `SSLSetProtocolVersionMin` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:295:5: warning[possibly-missing-attribute] Attribute `SSLSetProtocolVersionMax` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:296:5: warning[possibly-missing-attribute] Attribute `SSLSetProtocolVersionMax` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:299:9: warning[possibly-missing-attribute] Attribute `SSLSetALPNProtocols` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:300:9: warning[possibly-missing-attribute] Attribute `SSLSetALPNProtocols` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:305:5: warning[possibly-missing-attribute] Attribute `SecCopyErrorMessageString` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:306:5: warning[possibly-missing-attribute] Attribute `SecCopyErrorMessageString` may be missing on object of type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:308:5: error[invalid-assignment] Object of type `type[_CFunctionType]` is not assignable to attribute `SSLReadFunc` on type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:309:5: error[invalid-assignment] Object of type `type[_CFunctionType]` is not assignable to attribute `SSLWriteFunc` on type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:310:5: error[invalid-assignment] Object of type `type[_Pointer[c_void_p]]` is not assignable to attribute `SSLContextRef` on type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:311:5: error[invalid-assignment] Object of type `<class 'c_uint32'>` is not assignable to attribute `SSLProtocol` on type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:312:5: error[invalid-assignment] Object of type `<class 'c_uint32'>` is not assignable to attribute `SSLCipherSuite` on type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:313:5: error[invalid-assignment] Object of type `type[_Pointer[c_void_p]]` is not assignable to attribute `SecIdentityRef` on type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:314:5: error[invalid-assignment] Object of type `type[_Pointer[c_void_p]]` is not assignable to attribute `SecKeychainRef` on type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:315:5: error[invalid-assignment] Object of type `type[_Pointer[c_void_p]]` is not assignable to attribute `SecTrustRef` on type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:316:5: error[invalid-assignment] Object of type `<class 'c_uint32'>` is not assignable to attribute `SecTrustResultType` on type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:317:5: error[invalid-assignment] Object of type `<class 'c_uint32'>` is not assignable to attribute `SecExternalFormat` on type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:318:5: error[invalid-assignment] Object of type `<class 'c_int32'>` is not assignable to attribute `OSStatus` on type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:320:5: error[invalid-assignment] Object of type `_Pointer[c_void_p]` is not assignable to attribute `kSecImportExportPassphrase` on type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:321:9: error[invalid-argument-type] Argument to bound method `in_dll` is incorrect: Expected `CDLL`, found `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:323:5: error[invalid-assignment] Object of type `_Pointer[c_void_p]` is not assignable to attribute `kSecImportItemIdentity` on type `CDLL | None`
+ src/pip/_vendor/urllib3/contrib/_securetransport/bindings.py:324:9: error[invalid-argument-type] Argument to bound method `in_dll` is 

... (truncated 65012 lines) ...
Memory usage changes were detected when running on open source projects
trio (https://github.com/python-trio/trio)
-     struct metadata = ~10MB
+     struct metadata = ~11MB
-     struct fields = ~11MB
+     struct fields = ~12MB
-     memo fields = ~108MB
+     memo fields = ~113MB

prefect (https://github.com/PrefectHQ/prefect)
-     memo metadata = ~167MB
+     memo metadata = ~176MB

@mtshiba

This comment was marked as resolved.

@AlexWaygood AlexWaygood added the ty The ty type checker label Apr 13, 2025
@sharkdp

This comment was marked as resolved.

@mtshiba

mtshiba commented Apr 15, 2025

Copy link
Copy Markdown
Collaborator Author

If a function contains a yield expression, i.e. if it is a generator, current type inference is incorrect. But supporting this requires solving another issues, so I will leave it as a TODO for now.

As for return type inference for normal functions, I think the work is completed.

@AlexWaygood
AlexWaygood removed their request for review April 15, 2025 17:42
@mtshiba
mtshiba force-pushed the infer-return-type branch 4 times, most recently from 3ba99d1 to 35f4a75 Compare May 8, 2025 15:56
@MichaReiser MichaReiser changed the title [red-knot] infer function's return type [ty] infer function's return type May 8, 2025
@mtshiba
mtshiba force-pushed the infer-return-type branch from 404c1da to 80f2b5c Compare May 8, 2025 17:35
@carljm

carljm commented May 9, 2025

Copy link
Copy Markdown
Contributor

Sorry that I haven't gotten around to reviewing this PR yet. There's just been a lot to do, and providing this feature is lower on my priority list than some other features. But I realize that places a burden on you to keep it up to date with (rapidly changing) main branch. But I will try to find time to review it soon.

@mtshiba
mtshiba force-pushed the infer-return-type branch from 0a16b46 to 126aef8 Compare May 11, 2025 12:18
@mtshiba
mtshiba force-pushed the infer-return-type branch from 91c66c1 to 22e8594 Compare May 11, 2025 12:45
@mtshiba
mtshiba force-pushed the infer-return-type branch from 22e8594 to 391ee91 Compare May 11, 2025 12:50

@carljm carljm left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review here; plane is landing now so submitting the comments I have. Will come back to this later.

Thank you for working on this, and sorry for the slow review! It's a very useful feature.

Comment thread crates/ty_python_semantic/src/types.rs Resolved
@astral-sh-bot

astral-sh-bot Bot commented Dec 19, 2025

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
unsupported-operator 35,575 0 73
possibly-missing-attribute 15,046 86 339
invalid-argument-type 3,481 82 239
non-subscriptable 2,222 0 0
invalid-assignment 1,638 11 33
not-iterable 1,341 0 8
unresolved-attribute 1,209 12 3
no-matching-overload 728 0 0
call-non-callable 703 2 0
invalid-return-type 363 2 26
too-many-positional-arguments 290 3 0
unknown-argument 146 8 0
unsupported-base 145 0 0
invalid-await 115 0 6
invalid-key 115 0 0
unused-ignore-comment 20 83 0
missing-argument 44 4 0
index-out-of-bounds 43 4 0
parameter-already-assigned 2 19 0
division-by-zero 8 0 0
invalid-context-manager 7 0 0
deprecated 3 2 0
invalid-type-form 2 0 0
possibly-unresolved-reference 0 2 0
invalid-exception-caught 1 0 0
invalid-method-override 1 0 0
Total 63,248 320 727

@mtshiba
mtshiba marked this pull request as ready for review December 19, 2025 17:25
@mtshiba
mtshiba requested a review from carljm December 19, 2025 17:26
@MichaReiser

Copy link
Copy Markdown
Member

Given the many new diagnostics, I think we should consider adding a new analysis.<option> to control whether return type inference is on.

I also suggest running the ty-benchmarks on this o get a better sense for the performance impact (note that ty-benchmarks turns off return type inference for all other type checkers that support it for a fair comparison)

if self
.signature_type
.as_bound_method()
.is_none_or(|method| !method.is_init(self.db))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This addresses a pattern that was not considered in #22068, but I'm not sure if this is the best approach.

@carljm carljm self-assigned this Feb 14, 2026
KotlinIsland pushed a commit to KotlinIsland/basedpython that referenced this pull request May 1, 2026
## Summary

From #17371

In #17371, `DivergentType` was introduced to prevent type inference for
recursive functions from diverging and causing panics. This turned out
to be useful for other divergent type inferences
(astral-sh/ruff#17371 (comment)),
so I extracted the introduction part of `DivergentType` into this PR so
that we can use it without waiting for the merge of #17371.

Note that this PR only introduces `DivergentType` and does not actually
address divergent type inference yet. Please refer to
https://github.com/astral-sh/ruff/pull/17371/files#diff-20b910c6e20faa962bb1642e111db1cbad8e66ace089bdd966ac9d7f9fa99ff2R542-R622
etc. when implementing handling of divergence suppression using this
type.

## Test Plan

---------

Co-authored-by: Carl Meyer <[email protected]>
@lerebear
lerebear removed request for dcreager and sharkdp June 15, 2026 22:33
sharkdp added a commit that referenced this pull request Oct 15, 2026
## Summary

<img width="331" height="155" alt="image"
src="https://github.com/user-attachments/assets/8e1b5c40-57b7-44ec-a197-3770e9fc3236"
align=right />


This PR adds return type inference as a new feature to ty. The feature
is currently *disabled by default*. Users can activate the feature by
setting `analysis.return-type-inference` to `"always"`.

In a standalone function, the inferred return type is simply the union
of the types of all reachable `return`ed expressions, as shown in the
image on the right. If control flow can reach the end of the function
scope, we add `None` to the union. In a (non-final) method on a
(non-final) class, we additionally union with `Unknown` to allow child
classes to widen the intended return type. For example, imagine

```py
class TaskBase:
    def compute(self):
        return None

class IntTask(TaskBase):
    def compute(self):
        return 42
```

Here, we infer a return type of `None | Unknown` for `TaskBase.compute`.
Otherwise, if we inferred `None`, we would prohibit child classes from
returning something else, which seems undesirable. Another interesting
scenario is when the base class method is annotated, but the child class
method is not:

```py
class Base:
    def method(self) -> int:
        return 0

class Child(Base):
    def method(self):
        return 1
```
Here, we respect the base class definition and infer `Child.method` as
returning `int`, not `int | Unknown`.

This work is based on #17371 by
@mtshiba (thank you!)

There are a few notable things that are _not_ implemented here:
- The type of the function itself currently stays unchanged, that is: we
do not infer a signature with the inferred return type. Concretely:
`my_function()` may be inferred as `int`, but `my_function` itself would
still be inferred as `def my_function() -> Unknown`. We have existing
tests with TODOs for this and I plan to tackle this in a follow up.
- We do not yet have return type inference for generator functions or
async functions
- We do not attempt to solve the problem of "escaping" inner types here
(see tests with TODOs)
- We do not add LSP/playground features related to this feature, but
plan to do so soon (display return type hints).
- There is a limitation around `functools.wraps` that's present in the
ecosystem report. This will hopefully be solved by
python/typeshed#16515
- There is a [limitation around
`NotImplemented`](astral-sh/ty#1150 (comment))
which hasn't been resolved yet. The solution is described
[here](astral-sh/ty#1150 (comment)).
- Fixpoint iteration currently uses `Divergent` as a provisional value.
I did think about using the new μ-types, but that currently leaves too
many questions unanswered: How would we represent an anonymous μ-type?
How would the (provisional) recursive marker `R` interact with other
types during inference (especially since those operations require
"closed" recursive types, and `R` would still be open)?


closes astral-sh/ty#128

## Test Plan

- Changed assertions in the previously reviewed & merged mdtests
- Studied the ecosystem impact and addressed many problems

---------

Co-authored-by: Shunsuke Shibayama <[email protected]>
@sharkdp

sharkdp commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Superseded by #29253, which includes major parts of the implementation here. Thank you @mtshiba!

@sharkdp sharkdp closed this Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ecosystem-analyzer ty The ty type checker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return type inference

5 participants