ruff/scripts
David Peter a9be810c38
[ty] Type inference for `@asynccontextmanager` (#21876)
## Summary

This PR adds special handling for `asynccontextmanager` calls as a
temporary solution for https://github.com/astral-sh/ty/issues/1804. We
will be able to remove this soon once we have support for generic
protocols in the solver.

closes https://github.com/astral-sh/ty/issues/1804

## Ecosystem

```diff
+ tests/test_downloadermiddleware.py:305:56: error[invalid-argument-type] Argument to bound method `download` is incorrect: Expected `Spider`, found `Unknown | Spider | None`
+ tests/test_downloadermiddleware.py:305:56: warning[possibly-missing-attribute] Attribute `spider` may be missing on object of type `Crawler | None`
```
These look like true positives

```diff
+ pymongo/asynchronous/database.py:1021:35: error[invalid-assignment] Object of type `(AsyncClientSession & ~AlwaysTruthy & ~AlwaysFalsy) | (_ServerMode & ~AlwaysFalsy) | Unknown | Primary` is not assignable to `_ServerMode | None`
+ pymongo/asynchronous/database.py:1025:17: error[invalid-argument-type] Argument to bound method `_conn_for_reads` is incorrect: Expected `_ServerMode`, found `_ServerMode | None`
```

Known problems or true positives, just caused by the new type for
`session`

```diff
- src/integrations/prefect-sqlalchemy/prefect_sqlalchemy/database.py:269:16: error[invalid-return-type] Return type does not match returned value: expected `Connection | AsyncConnection`, found `_GeneratorContextManager[Unknown, None, None] | _AsyncGeneratorContextManager[Unknown, None] | Connection | AsyncConnection`
+ src/integrations/prefect-sqlalchemy/prefect_sqlalchemy/database.py:269:16: error[invalid-return-type] Return type does not match returned value: expected `Connection | AsyncConnection`, found `_GeneratorContextManager[Unknown, None, None] | _AsyncGeneratorContextManager[AsyncConnection, None] | Connection | AsyncConnection`
```

Just a more concrete type

```diff
- src/prefect/flow_engine.py:1277:24: error[missing-argument] No argument provided for required parameter `cls`
- src/prefect/server/api/server.py:696:49: error[missing-argument] No argument provided for required parameter `cls`
- src/prefect/task_engine.py:1426:24: error[missing-argument] No argument provided for required parameter `cls`
```

Good

## Test Plan

* Adapted and newly added Markdown tests
* Tested on internal codebase
2025-12-09 22:49:00 +01:00
..
benchmarks Bump 0.14.8 (#21791) 2025-12-04 09:45:53 -05:00
release Add shellcheck to pre-commit (#19361) 2025-07-15 16:49:13 +00:00
ty_benchmark [ty] Update benchmark dependencies (#21815) 2025-12-05 17:23:18 +01:00
Dockerfile.ecosystem Remove outdated feature flag from Dockerfile.ecosystem (#4620) 2023-05-24 08:19:08 +00:00
_utils.py Use `__future__` imports in scripts (#5301) 2023-06-22 11:40:16 -04:00
add_plugin.py [`pydoclint`] Implement `docstring-missing-exception` and `docstring-extraneous-exception` (`DOC501`, `DOC502`) (#11471) 2024-07-20 19:41:51 +00:00
add_rule.py Dogfood ty on the `scripts` directory (#21617) 2025-11-24 23:13:44 +00:00
check_docs_formatted.py [`pycodestyle`] Make example not raise unnecessary `SyntaxError` (`E114`) (#19190) 2025-07-08 10:00:14 -04:00
check_ecosystem.py [ty] Type inference for `@asynccontextmanager` (#21876) 2025-12-09 22:49:00 +01:00
codemod_docstrings.sh [ty] Bump docstring-adder pin (#19606) 2025-07-28 22:59:56 +01:00
ecosystem_all_check.py Update pre-commit dependencies (#10698) 2024-04-06 23:00:41 +00:00
ecosystem_all_check.sh Rename `Autofix` to `Fix` (#7657) 2023-09-28 10:53:05 +00:00
ecosystem_all_check_entrypoint.sh Make ecosystem all check more generic (#4629) 2023-05-24 16:26:23 +02:00
formatter_ecosystem_checks.sh Improve the performance of the formatter instability check job (#14471) 2024-11-20 08:55:10 -06:00
generate_builtin_modules.py Use `#[expect(lint)]` over `#[allow(lint)]` where possible (#17822) 2025-05-03 21:20:31 +02:00
generate_known_standard_library.py python_stdlib: update for 3.14 (#18014) 2025-05-11 11:25:54 -05:00
generate_mkdocs.py Update editor integrations link in README (#17977) 2025-05-26 09:50:09 +01:00
mypy_primer.sh [ty] Keep colorizing `mypy_primer` output (#21515) 2025-11-19 08:52:51 +00:00
pyproject.toml Dogfood ty on the `scripts` directory (#21617) 2025-11-24 23:13:44 +00:00
release.sh Bump v0.14.3 (#21152) 2025-10-30 17:06:29 -07:00
transform_readme.py Update pre-commit dependencies (#10698) 2024-04-06 23:00:41 +00:00
update_ambiguous_characters.py Dogfood ty on the `scripts` directory (#21617) 2025-11-24 23:13:44 +00:00
update_schemastore.py Use `npm ci --ignore-scripts` everywhere (#21742) 2025-12-01 17:13:52 -05:00