From b1805d1b9920ebeed95bc949bc09204ab442164b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 22:00:45 -0700 Subject: [PATCH] Bump ruff from 0.5.2 to 0.6.5 (#331) * Bump ruff from 0.5.2 to 0.6.5 Bumps [ruff](https://github.com/astral-sh/ruff) from 0.5.2 to 0.6.5. - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](https://github.com/astral-sh/ruff/compare/0.5.2...0.6.5) --- updated-dependencies: - dependency-name: ruff dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Set ruff target-version to py310 * Use latest version of ruff * ruff check --fix --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jack Collins <6640905+jackmpcollins@users.noreply.github.com> --- docs/examples/registering_custom_type.ipynb | 3 +- poetry.lock | 51 ++++++++----------- pyproject.toml | 3 +- src/magentic/_pydantic.py | 3 +- src/magentic/chat.py | 5 +- .../chat_model/anthropic_chat_model.py | 11 +++- src/magentic/chat_model/litellm_chat_model.py | 4 +- src/magentic/chat_model/message.py | 12 ++--- src/magentic/chat_model/mistral_chat_model.py | 3 +- src/magentic/chat_model/openai_chat_model.py | 11 +++- src/magentic/chatprompt.py | 4 +- src/magentic/function_call.py | 11 ++-- src/magentic/prompt_chain.py | 2 +- src/magentic/prompt_function.py | 4 +- src/magentic/streaming.py | 4 +- src/magentic/typing.py | 3 +- tests/chat_model/test_litellm_chat_model.py | 3 +- tests/test_chat.py | 5 +- tests/test_function_call.py | 5 +- tests/test_prompt_function.py | 3 +- tests/test_streaming.py | 2 +- tests/test_typing.py | 3 +- 22 files changed, 81 insertions(+), 74 deletions(-) diff --git a/docs/examples/registering_custom_type.ipynb b/docs/examples/registering_custom_type.ipynb index 142a38ae..e4f6a5fb 100644 --- a/docs/examples/registering_custom_type.ipynb +++ b/docs/examples/registering_custom_type.ipynb @@ -20,7 +20,8 @@ "# Create FunctionSchema for pd.DataFrame\n", "\n", "import json\n", - "from typing import Any, Iterable\n", + "from collections.abc import Iterable\n", + "from typing import Any\n", "\n", "import pandas as pd\n", "\n", diff --git a/poetry.lock b/poetry.lock index 542ee17a..16e41f2e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -3292,7 +3292,6 @@ files = [ {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, - {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, @@ -3300,16 +3299,8 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, - {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, - {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, - {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, - {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, @@ -3326,7 +3317,6 @@ files = [ {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, - {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, @@ -3334,7 +3324,6 @@ files = [ {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, - {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, @@ -3773,29 +3762,29 @@ files = [ [[package]] name = "ruff" -version = "0.5.2" +version = "0.6.7" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.5.2-py3-none-linux_armv6l.whl", hash = "sha256:7bab8345df60f9368d5f4594bfb8b71157496b44c30ff035d1d01972e764d3be"}, - {file = "ruff-0.5.2-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:1aa7acad382ada0189dbe76095cf0a36cd0036779607c397ffdea16517f535b1"}, - {file = "ruff-0.5.2-py3-none-macosx_11_0_arm64.whl", hash = "sha256:aec618d5a0cdba5592c60c2dee7d9c865180627f1a4a691257dea14ac1aa264d"}, - {file = "ruff-0.5.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0b62adc5ce81780ff04077e88bac0986363e4a3260ad3ef11ae9c14aa0e67ef"}, - {file = "ruff-0.5.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:dc42ebf56ede83cb080a50eba35a06e636775649a1ffd03dc986533f878702a3"}, - {file = "ruff-0.5.2-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c15c6e9f88c67ffa442681365d11df38afb11059fc44238e71a9d9f1fd51de70"}, - {file = "ruff-0.5.2-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:d3de9a5960f72c335ef00763d861fc5005ef0644cb260ba1b5a115a102157251"}, - {file = "ruff-0.5.2-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:fe5a968ae933e8f7627a7b2fc8893336ac2be0eb0aace762d3421f6e8f7b7f83"}, - {file = "ruff-0.5.2-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:a04f54a9018f75615ae52f36ea1c5515e356e5d5e214b22609ddb546baef7132"}, - {file = "ruff-0.5.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1ed02fb52e3741f0738db5f93e10ae0fb5c71eb33a4f2ba87c9a2fa97462a649"}, - {file = "ruff-0.5.2-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:3cf8fe659f6362530435d97d738eb413e9f090e7e993f88711b0377fbdc99f60"}, - {file = "ruff-0.5.2-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:237a37e673e9f3cbfff0d2243e797c4862a44c93d2f52a52021c1a1b0899f846"}, - {file = "ruff-0.5.2-py3-none-musllinux_1_2_i686.whl", hash = "sha256:2a2949ce7c1cbd8317432ada80fe32156df825b2fd611688814c8557824ef060"}, - {file = "ruff-0.5.2-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:481af57c8e99da92ad168924fd82220266043c8255942a1cb87958b108ac9335"}, - {file = "ruff-0.5.2-py3-none-win32.whl", hash = "sha256:f1aea290c56d913e363066d83d3fc26848814a1fed3d72144ff9c930e8c7c718"}, - {file = "ruff-0.5.2-py3-none-win_amd64.whl", hash = "sha256:8532660b72b5d94d2a0a7a27ae7b9b40053662d00357bb2a6864dd7e38819084"}, - {file = "ruff-0.5.2-py3-none-win_arm64.whl", hash = "sha256:73439805c5cb68f364d826a5c5c4b6c798ded6b7ebaa4011f01ce6c94e4d5583"}, - {file = "ruff-0.5.2.tar.gz", hash = "sha256:2c0df2d2de685433794a14d8d2e240df619b748fbe3367346baa519d8e6f1ca2"}, + {file = "ruff-0.6.7-py3-none-linux_armv6l.whl", hash = "sha256:08277b217534bfdcc2e1377f7f933e1c7957453e8a79764d004e44c40db923f2"}, + {file = "ruff-0.6.7-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:c6707a32e03b791f4448dc0dce24b636cbcdee4dd5607adc24e5ee73fd86c00a"}, + {file = "ruff-0.6.7-py3-none-macosx_11_0_arm64.whl", hash = "sha256:533d66b7774ef224e7cf91506a7dafcc9e8ec7c059263ec46629e54e7b1f90ab"}, + {file = "ruff-0.6.7-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:17a86aac6f915932d259f7bec79173e356165518859f94649d8c50b81ff087e9"}, + {file = "ruff-0.6.7-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:b3f8822defd260ae2460ea3832b24d37d203c3577f48b055590a426a722d50ef"}, + {file = "ruff-0.6.7-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9ba4efe5c6dbbb58be58dd83feedb83b5e95c00091bf09987b4baf510fee5c99"}, + {file = "ruff-0.6.7-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:525201b77f94d2b54868f0cbe5edc018e64c22563da6c5c2e5c107a4e85c1c0d"}, + {file = "ruff-0.6.7-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8854450839f339e1049fdbe15d875384242b8e85d5c6947bb2faad33c651020b"}, + {file = "ruff-0.6.7-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2f0b62056246234d59cbf2ea66e84812dc9ec4540518e37553513392c171cb18"}, + {file = "ruff-0.6.7-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6b1462fa56c832dc0cea5b4041cfc9c97813505d11cce74ebc6d1aae068de36b"}, + {file = "ruff-0.6.7-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:02b083770e4cdb1495ed313f5694c62808e71764ec6ee5db84eedd82fd32d8f5"}, + {file = "ruff-0.6.7-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:0c05fd37013de36dfa883a3854fae57b3113aaa8abf5dea79202675991d48624"}, + {file = "ruff-0.6.7-py3-none-musllinux_1_2_i686.whl", hash = "sha256:f49c9caa28d9bbfac4a637ae10327b3db00f47d038f3fbb2195c4d682e925b14"}, + {file = "ruff-0.6.7-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:a0e1655868164e114ba43a908fd2d64a271a23660195017c17691fb6355d59bb"}, + {file = "ruff-0.6.7-py3-none-win32.whl", hash = "sha256:a939ca435b49f6966a7dd64b765c9df16f1faed0ca3b6f16acdf7731969deb35"}, + {file = "ruff-0.6.7-py3-none-win_amd64.whl", hash = "sha256:590445eec5653f36248584579c06252ad2e110a5d1f32db5420de35fb0e1c977"}, + {file = "ruff-0.6.7-py3-none-win_arm64.whl", hash = "sha256:b28f0d5e2f771c1fe3c7a45d3f53916fc74a480698c4b5731f0bea61e52137c8"}, + {file = "ruff-0.6.7.tar.gz", hash = "sha256:44e52129d82266fa59b587e2cd74def5637b730a69c4542525dfdecfaae38bd5"}, ] [[package]] @@ -4531,4 +4520,4 @@ litellm = ["litellm"] [metadata] lock-version = "2.0" python-versions = ">=3.10,<4.0" -content-hash = "81037825d20d0e111516496924acc94599815623031edf1ef6b965092861693d" +content-hash = "85c9c8fcdee1919d34c0b6230bedd1b12f406a21aa3da0103c2dcacf54a2cbb8" diff --git a/pyproject.toml b/pyproject.toml index 3e186048..3f013346 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,7 @@ pytest-asyncio = "*" pytest-clarity = "*" pytest-cov = "*" python-dotenv = "^1.0.1" -ruff = ">=0.3,<0.6" +ruff = "^0.6.7" [tool.poetry.group.docs.dependencies] mkdocs = "^1.5.3" @@ -77,6 +77,7 @@ markers = [ [tool.ruff] include = ["*.py", "*.pyi", "**/pyproject.toml", "*.ipynb"] +target-version = "py310" # Use `ruff linter` to list available linters # https://beta.ruff.rs/docs/rules/ diff --git a/src/magentic/_pydantic.py b/src/magentic/_pydantic.py index 392b6ebf..419c8843 100644 --- a/src/magentic/_pydantic.py +++ b/src/magentic/_pydantic.py @@ -1,4 +1,5 @@ -from typing import Any, Callable, TypeVar +from collections.abc import Callable +from typing import Any, TypeVar import openai from pydantic import BaseModel diff --git a/src/magentic/chat.py b/src/magentic/chat.py index 2e0dbab7..66583cdf 100644 --- a/src/magentic/chat.py +++ b/src/magentic/chat.py @@ -1,5 +1,6 @@ import inspect -from typing import Any, Callable, Iterable, ParamSpec, TypeVar +from collections.abc import Callable, Iterable +from typing import Any, ParamSpec, TypeVar from magentic.backend import get_chat_model from magentic.chat_model.base import ChatModel @@ -121,7 +122,7 @@ def exec_function_call(self: Self) -> Self: parallel_function_call = self.last_message.content chat = self for result, function_call in zip( - parallel_function_call(), parallel_function_call + parallel_function_call(), parallel_function_call, strict=True ): chat = chat.add_message( FunctionResultMessage(content=result, function_call=function_call) diff --git a/src/magentic/chat_model/anthropic_chat_model.py b/src/magentic/chat_model/anthropic_chat_model.py index bd2aa621..dc54d567 100644 --- a/src/magentic/chat_model/anthropic_chat_model.py +++ b/src/magentic/chat_model/anthropic_chat_model.py @@ -1,10 +1,17 @@ import base64 import json -from collections.abc import AsyncIterator, Callable, Iterable, Iterator +from collections.abc import ( + AsyncIterable, + AsyncIterator, + Callable, + Iterable, + Iterator, + Sequence, +) from enum import Enum from functools import singledispatch from itertools import chain, groupby -from typing import Any, AsyncIterable, Generic, Sequence, TypeVar, cast, overload +from typing import Any, Generic, TypeVar, cast, overload import filetype from pydantic import ValidationError diff --git a/src/magentic/chat_model/litellm_chat_model.py b/src/magentic/chat_model/litellm_chat_model.py index 34cda228..68ea72f5 100644 --- a/src/magentic/chat_model/litellm_chat_model.py +++ b/src/magentic/chat_model/litellm_chat_model.py @@ -1,6 +1,6 @@ -from collections.abc import Callable, Iterable +from collections.abc import Callable, Iterable, Sequence from itertools import chain -from typing import Any, Sequence, TypeVar, cast, overload +from typing import Any, TypeVar, cast, overload from openai.types.chat import ChatCompletionToolChoiceOptionParam diff --git a/src/magentic/chat_model/message.py b/src/magentic/chat_model/message.py index 97d947e2..6049c4cb 100644 --- a/src/magentic/chat_model/message.py +++ b/src/magentic/chat_model/message.py @@ -1,13 +1,12 @@ from abc import ABC, abstractmethod +from collections.abc import Awaitable from typing import ( Annotated, Any, - Awaitable, Generic, Literal, NamedTuple, TypeVar, - Union, cast, get_origin, overload, @@ -210,13 +209,8 @@ def format(self, **kwargs: Any) -> "FunctionResultMessage[ContentT]": AnyMessage = Annotated[ - Union[ - SystemMessage, - UserMessage, - AssistantMessage[Any], - ToolResultMessage[Any], - # Do not include FunctionResultMessage which also uses "tool" role - ], + # Do not include FunctionResultMessage which also uses "tool" role + SystemMessage | UserMessage | AssistantMessage[Any] | ToolResultMessage[Any], Field(discriminator="role"), ] """Union of all message types.""" diff --git a/src/magentic/chat_model/mistral_chat_model.py b/src/magentic/chat_model/mistral_chat_model.py index 8b6a3a18..b9a28df7 100644 --- a/src/magentic/chat_model/mistral_chat_model.py +++ b/src/magentic/chat_model/mistral_chat_model.py @@ -1,6 +1,7 @@ import os +from collections.abc import Callable, Iterable, Sequence from enum import Enum -from typing import Any, Callable, Iterable, Sequence, TypeVar, overload +from typing import Any, TypeVar, overload import openai from openai.types.chat import ChatCompletionStreamOptionsParam diff --git a/src/magentic/chat_model/openai_chat_model.py b/src/magentic/chat_model/openai_chat_model.py index f8f644f8..c2eaf146 100644 --- a/src/magentic/chat_model/openai_chat_model.py +++ b/src/magentic/chat_model/openai_chat_model.py @@ -1,9 +1,16 @@ import base64 -from collections.abc import AsyncIterable, AsyncIterator, Callable, Iterable, Iterator +from collections.abc import ( + AsyncIterable, + AsyncIterator, + Callable, + Iterable, + Iterator, + Sequence, +) from enum import Enum from functools import singledispatch, wraps from itertools import chain, groupby -from typing import Any, Generic, Literal, ParamSpec, Sequence, TypeVar, cast, overload +from typing import Any, Generic, Literal, ParamSpec, TypeVar, cast, overload import filetype import openai diff --git a/src/magentic/chatprompt.py b/src/magentic/chatprompt.py index edc5dfd7..906d3b38 100644 --- a/src/magentic/chatprompt.py +++ b/src/magentic/chatprompt.py @@ -1,13 +1,11 @@ import inspect +from collections.abc import Awaitable, Callable, Sequence from functools import update_wrapper from typing import ( Any, - Awaitable, - Callable, Generic, ParamSpec, Protocol, - Sequence, TypeVar, cast, overload, diff --git a/src/magentic/function_call.py b/src/magentic/function_call.py index b8cc9859..cb614484 100644 --- a/src/magentic/function_call.py +++ b/src/magentic/function_call.py @@ -1,16 +1,17 @@ import asyncio import inspect -from typing import ( - Any, +from collections.abc import ( AsyncIterable, AsyncIterator, Awaitable, Callable, - Generic, Iterable, Iterator, +) +from typing import ( + Any, + Generic, ParamSpec, - Tuple, TypeVar, cast, ) @@ -99,7 +100,7 @@ class AsyncParallelFunctionCall(Generic[T]): def __init__(self, function_calls: AsyncIterable[FunctionCall[Awaitable[T] | T]]): self._function_calls = CachedAsyncIterable(function_calls) - async def __call__(self) -> Tuple[T, ...]: + async def __call__(self) -> tuple[T, ...]: with logfire.span("Executing async parallel function call"): tasks_and_results: list[asyncio.Task[T] | T] = [] async for function_call in self._function_calls: diff --git a/src/magentic/prompt_chain.py b/src/magentic/prompt_chain.py index 6b2ef561..dda2e7fc 100644 --- a/src/magentic/prompt_chain.py +++ b/src/magentic/prompt_chain.py @@ -1,8 +1,8 @@ import inspect +from collections.abc import Callable from functools import wraps from typing import ( Any, - Callable, ParamSpec, TypeVar, cast, diff --git a/src/magentic/prompt_function.py b/src/magentic/prompt_function.py index 0e8b6604..4959b3b1 100644 --- a/src/magentic/prompt_function.py +++ b/src/magentic/prompt_function.py @@ -1,14 +1,12 @@ import copy import inspect +from collections.abc import Awaitable, Callable, Sequence from functools import update_wrapper from typing import ( Any, - Awaitable, - Callable, Generic, ParamSpec, Protocol, - Sequence, TypeVar, cast, overload, diff --git a/src/magentic/streaming.py b/src/magentic/streaming.py index dd0451ae..c3154167 100644 --- a/src/magentic/streaming.py +++ b/src/magentic/streaming.py @@ -1,9 +1,9 @@ import asyncio import textwrap -from collections.abc import AsyncIterable, Iterable +from collections.abc import AsyncIterable, AsyncIterator, Callable, Iterable, Iterator from dataclasses import dataclass from itertools import chain, dropwhile -from typing import Any, AsyncIterator, Callable, Iterator, TypeVar +from typing import Any, TypeVar T = TypeVar("T") diff --git a/src/magentic/typing.py b/src/magentic/typing.py index 8d9b684e..21045e92 100644 --- a/src/magentic/typing.py +++ b/src/magentic/typing.py @@ -1,9 +1,8 @@ import inspect import types -from collections.abc import Mapping, Sequence +from collections.abc import Iterable, Mapping, Sequence from typing import ( Any, - Iterable, TypeGuard, TypeVar, Union, diff --git a/tests/chat_model/test_litellm_chat_model.py b/tests/chat_model/test_litellm_chat_model.py index c49016d5..889ff924 100644 --- a/tests/chat_model/test_litellm_chat_model.py +++ b/tests/chat_model/test_litellm_chat_model.py @@ -1,4 +1,5 @@ -from typing import Annotated, Any, Iterator +from collections.abc import Iterator +from typing import Annotated, Any import litellm import pytest diff --git a/tests/test_chat.py b/tests/test_chat.py index cdb21c3b..5a6091a7 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -1,4 +1,4 @@ -from typing import Awaitable +from typing import TYPE_CHECKING import pytest @@ -16,6 +16,9 @@ from magentic.prompt_function import prompt from magentic.streaming import async_iter +if TYPE_CHECKING: + from collections.abc import Awaitable + def test_chat_from_prompt(): """Test creating a chat from a prompt function.""" diff --git a/tests/test_function_call.py b/tests/test_function_call.py index 1cbac4aa..d05afd37 100644 --- a/tests/test_function_call.py +++ b/tests/test_function_call.py @@ -1,5 +1,5 @@ import inspect -from typing import Awaitable +from typing import TYPE_CHECKING import pytest from typing_extensions import assert_type @@ -11,6 +11,9 @@ ) from magentic.streaming import async_iter +if TYPE_CHECKING: + from collections.abc import Awaitable + def plus(a: int, b: int) -> int: return a + b diff --git a/tests/test_prompt_function.py b/tests/test_prompt_function.py index 75034c7d..8da3fa7f 100644 --- a/tests/test_prompt_function.py +++ b/tests/test_prompt_function.py @@ -1,7 +1,8 @@ """Tests for PromptFunction.""" +from collections.abc import Awaitable from inspect import getdoc -from typing import Annotated, Awaitable +from typing import Annotated from unittest.mock import AsyncMock, Mock import pytest diff --git a/tests/test_streaming.py b/tests/test_streaming.py index 71ff9085..574a233c 100644 --- a/tests/test_streaming.py +++ b/tests/test_streaming.py @@ -1,4 +1,4 @@ -from typing import AsyncIterator +from collections.abc import AsyncIterator import pytest diff --git a/tests/test_typing.py b/tests/test_typing.py index 47bc110a..ae1646ac 100644 --- a/tests/test_typing.py +++ b/tests/test_typing.py @@ -1,6 +1,7 @@ import typing +from collections.abc import Iterable from types import NoneType -from typing import Any, Generic, Iterable, TypeVar +from typing import Any, Generic, TypeVar import pytest from pydantic import BaseModel