From 185ff789d0e6257fc6c181ec52c378ee00324c94 Mon Sep 17 00:00:00 2001 From: Mani Mozaffar Date: Sat, 23 Mar 2024 21:45:02 +0300 Subject: [PATCH] Add support for python 3.9~3.11 --- .envrc | 5 ++ .github/workflows/main.yml | 3 +- examples/basic1.py | 1 + examples/basic2.py | 1 + examples/basic3.py | 2 + fastexchange/converter/base_client.py | 3 +- fastexchange/converter/mappings.py | 3 +- fastexchange/crypto/schema.py | 10 ++-- fastexchange/crypto/usdt.py | 4 +- fastexchange/currency.py | 3 +- fastexchange/http.py | 6 +-- poetry.lock | 78 +++++++-------------------- pyproject.toml | 4 +- tox.ini | 7 ++- 14 files changed, 51 insertions(+), 79 deletions(-) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..f2555c5 --- /dev/null +++ b/.envrc @@ -0,0 +1,5 @@ +VIRTUAL_ENV="$(pwd)/.venv" +PATH=$VIRTUAL_ENV/bin:$PATH +export VIRTUAL_ENV +export PATH +export POETRY_ACTIVE=1 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5ce3415..b71f41d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.8', '3.9', '3.10', '3.11'] + python-version: ["3.9", "3.10", "3.11"] fail-fast: false steps: - name: Check out @@ -57,7 +57,6 @@ jobs: - name: Test with tox run: tox - check-docs: runs-on: ubuntu-latest steps: diff --git a/examples/basic1.py b/examples/basic1.py index 0cca7f3..14d9bac 100644 --- a/examples/basic1.py +++ b/examples/basic1.py @@ -1,3 +1,4 @@ +# type: ignore from decimal import Decimal from fastexchange.currency import EURCurrency, USDCurrency diff --git a/examples/basic2.py b/examples/basic2.py index 0e36b65..2e96aa1 100644 --- a/examples/basic2.py +++ b/examples/basic2.py @@ -1,3 +1,4 @@ +# type: ignore import asyncio from decimal import Decimal diff --git a/examples/basic3.py b/examples/basic3.py index 74b256c..2d20ff9 100644 --- a/examples/basic3.py +++ b/examples/basic3.py @@ -1,3 +1,5 @@ +# type: ignore + import asyncio from rich import print diff --git a/fastexchange/converter/base_client.py b/fastexchange/converter/base_client.py index ab5d7ac..ee27e29 100644 --- a/fastexchange/converter/base_client.py +++ b/fastexchange/converter/base_client.py @@ -1,4 +1,5 @@ from abc import ABC, abstractmethod +from typing import Union from typing_extensions import TypeVar @@ -13,7 +14,7 @@ class BaseConverter(ABC): mapping: dict[FromToExchange, str] - def __init__(self, client: BaseClient | None = None): + def __init__(self, client: Union[BaseClient, None] = None): self.client = client or get_client() def is_supported(self, from_: type[DiscriminatedCurrency], to: type[ToCurrency]) -> bool: diff --git a/fastexchange/converter/mappings.py b/fastexchange/converter/mappings.py index bd526f6..75ac8b0 100644 --- a/fastexchange/converter/mappings.py +++ b/fastexchange/converter/mappings.py @@ -1,7 +1,6 @@ from typing import NamedTuple -from ..currency import EURCurrency, USDCurrency -from .base_client import DiscriminatedCurrency +from ..currency import DiscriminatedCurrency, EURCurrency, USDCurrency class FromToExchange(NamedTuple): diff --git a/fastexchange/crypto/schema.py b/fastexchange/crypto/schema.py index 7395f72..5d55327 100644 --- a/fastexchange/crypto/schema.py +++ b/fastexchange/crypto/schema.py @@ -2,7 +2,7 @@ from datetime import datetime from decimal import Decimal -from typing import Annotated +from typing import Annotated, Union from pydantic import BaseModel, BeforeValidator, Field @@ -62,10 +62,10 @@ class TokenTransfer(BaseModel): riskTransaction: bool # allow to parse others - event_type: EventTypes | str = Field(union_mode="left_to_right") - contract_type: Network | str = Field(union_mode="left_to_right") - finalResult: Status | str = Field(union_mode="left_to_right") - contractRet: Status | str = Field(union_mode="left_to_right") + event_type: Union[EventTypes, str] = Field(union_mode="left_to_right") + contract_type: Union[Network, str] = Field(union_mode="left_to_right") + finalResult: Union[Status, str] = Field(union_mode="left_to_right") + contractRet: Union[Status, str] = Field(union_mode="left_to_right") def to_usd(self, current_rate: Decimal = Decimal(1)) -> USDCurrency: """We assume that 1 usdt == 1 usd, but in case this wasn't true, this method should get the current rate""" diff --git a/fastexchange/crypto/usdt.py b/fastexchange/crypto/usdt.py index 125c00d..a582c00 100644 --- a/fastexchange/crypto/usdt.py +++ b/fastexchange/crypto/usdt.py @@ -1,10 +1,12 @@ +from typing import Union + from fastexchange.http import BaseClient, get_client, validate_response from .schema import Transfers class Trc20Gateway: - def __init__(self, client: BaseClient | None = None): + def __init__(self, client: Union[BaseClient, None] = None): self.client = client or get_client() self.base_url = "https://apilist.tronscanapi.com/api/token_trc20" diff --git a/fastexchange/currency.py b/fastexchange/currency.py index da44d88..549aaf9 100644 --- a/fastexchange/currency.py +++ b/fastexchange/currency.py @@ -1,9 +1,10 @@ from abc import ABC from decimal import Decimal from enum import auto -from typing import Annotated, Generic, Literal, TypeAlias, TypeVar, Union +from typing import Annotated, Generic, Literal, TypeVar, Union from pydantic import BaseModel, Field, TypeAdapter +from typing_extensions import TypeAlias from fastexchange.utils import StrEnum diff --git a/fastexchange/http.py b/fastexchange/http.py index cce88e2..079856f 100644 --- a/fastexchange/http.py +++ b/fastexchange/http.py @@ -2,7 +2,6 @@ from contextlib import contextmanager from functools import lru_cache from http.cookiejar import CookieJar -from typing import Self from httpx import AsyncClient from httpx._client import USE_CLIENT_DEFAULT, UseClientDefault @@ -20,16 +19,17 @@ TimeoutTypes, URLTypes, ) +from typing_extensions import Self class NullCookieJar(CookieJar): """A CookieJar that does not support setting cookie""" - def extract_cookies(self, *_): + def extract_cookies(self, *args, **kwargs): """For extracting and saving cookies. This implementation does nothing""" pass - def set_cookie(self, _): + def set_cookie(self, *args, **kwargs): """Normally for setting a cookie. This implementation does nothing""" pass diff --git a/poetry.lock b/poetry.lock index dc77934..2457029 100644 --- a/poetry.lock +++ b/poetry.lock @@ -792,64 +792,6 @@ files = [ griffe = ">=0.37" mkdocstrings = ">=0.20" -[[package]] -name = "mypy" -version = "1.9.0" -description = "Optional static typing for Python" -optional = false -python-versions = ">=3.8" -files = [ - {file = "mypy-1.9.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:f8a67616990062232ee4c3952f41c779afac41405806042a8126fe96e098419f"}, - {file = "mypy-1.9.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d357423fa57a489e8c47b7c85dfb96698caba13d66e086b412298a1a0ea3b0ed"}, - {file = "mypy-1.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:49c87c15aed320de9b438ae7b00c1ac91cd393c1b854c2ce538e2a72d55df150"}, - {file = "mypy-1.9.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:48533cdd345c3c2e5ef48ba3b0d3880b257b423e7995dada04248725c6f77374"}, - {file = "mypy-1.9.0-cp310-cp310-win_amd64.whl", hash = "sha256:4d3dbd346cfec7cb98e6cbb6e0f3c23618af826316188d587d1c1bc34f0ede03"}, - {file = "mypy-1.9.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:653265f9a2784db65bfca694d1edd23093ce49740b2244cde583aeb134c008f3"}, - {file = "mypy-1.9.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:3a3c007ff3ee90f69cf0a15cbcdf0995749569b86b6d2f327af01fd1b8aee9dc"}, - {file = "mypy-1.9.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2418488264eb41f69cc64a69a745fad4a8f86649af4b1041a4c64ee61fc61129"}, - {file = "mypy-1.9.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:68edad3dc7d70f2f17ae4c6c1b9471a56138ca22722487eebacfd1eb5321d612"}, - {file = "mypy-1.9.0-cp311-cp311-win_amd64.whl", hash = "sha256:85ca5fcc24f0b4aeedc1d02f93707bccc04733f21d41c88334c5482219b1ccb3"}, - {file = "mypy-1.9.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aceb1db093b04db5cd390821464504111b8ec3e351eb85afd1433490163d60cd"}, - {file = "mypy-1.9.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:0235391f1c6f6ce487b23b9dbd1327b4ec33bb93934aa986efe8a9563d9349e6"}, - {file = "mypy-1.9.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d4d5ddc13421ba3e2e082a6c2d74c2ddb3979c39b582dacd53dd5d9431237185"}, - {file = "mypy-1.9.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:190da1ee69b427d7efa8aa0d5e5ccd67a4fb04038c380237a0d96829cb157913"}, - {file = "mypy-1.9.0-cp312-cp312-win_amd64.whl", hash = "sha256:fe28657de3bfec596bbeef01cb219833ad9d38dd5393fc649f4b366840baefe6"}, - {file = "mypy-1.9.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:e54396d70be04b34f31d2edf3362c1edd023246c82f1730bbf8768c28db5361b"}, - {file = "mypy-1.9.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:5e6061f44f2313b94f920e91b204ec600982961e07a17e0f6cd83371cb23f5c2"}, - {file = "mypy-1.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:81a10926e5473c5fc3da8abb04119a1f5811a236dc3a38d92015cb1e6ba4cb9e"}, - {file = "mypy-1.9.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:b685154e22e4e9199fc95f298661deea28aaede5ae16ccc8cbb1045e716b3e04"}, - {file = "mypy-1.9.0-cp38-cp38-win_amd64.whl", hash = "sha256:5d741d3fc7c4da608764073089e5f58ef6352bedc223ff58f2f038c2c4698a89"}, - {file = "mypy-1.9.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:587ce887f75dd9700252a3abbc9c97bbe165a4a630597845c61279cf32dfbf02"}, - {file = "mypy-1.9.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:f88566144752999351725ac623471661c9d1cd8caa0134ff98cceeea181789f4"}, - {file = "mypy-1.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:61758fabd58ce4b0720ae1e2fea5cfd4431591d6d590b197775329264f86311d"}, - {file = "mypy-1.9.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:e49499be624dead83927e70c756970a0bc8240e9f769389cdf5714b0784ca6bf"}, - {file = "mypy-1.9.0-cp39-cp39-win_amd64.whl", hash = "sha256:571741dc4194b4f82d344b15e8837e8c5fcc462d66d076748142327626a1b6e9"}, - {file = "mypy-1.9.0-py3-none-any.whl", hash = "sha256:a260627a570559181a9ea5de61ac6297aa5af202f06fd7ab093ce74e7181e43e"}, - {file = "mypy-1.9.0.tar.gz", hash = "sha256:3cc5da0127e6a478cddd906068496a97a7618a21ce9b54bde5bf7e539c7af974"}, -] - -[package.dependencies] -mypy-extensions = ">=1.0.0" -tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} -typing-extensions = ">=4.1.0" - -[package.extras] -dmypy = ["psutil (>=4.0)"] -install-types = ["pip"] -mypyc = ["setuptools (>=50)"] -reports = ["lxml"] - -[[package]] -name = "mypy-extensions" -version = "1.0.0" -description = "Type system extensions for programs checked with the mypy type checker." -optional = false -python-versions = ">=3.5" -files = [ - {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"}, - {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, -] - [[package]] name = "nodeenv" version = "1.8.0" @@ -1106,6 +1048,24 @@ tomli = {version = ">=2.0.1", markers = "python_version < \"3.11\""} docs = ["furo (>=2023.8.19)", "sphinx (<7.2)", "sphinx-autodoc-typehints (>=1.24)"] testing = ["covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)", "setuptools (>=68.1.2)", "wheel (>=0.41.2)"] +[[package]] +name = "pyright" +version = "1.1.350" +description = "Command line wrapper for pyright" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pyright-1.1.350-py3-none-any.whl", hash = "sha256:f1dde6bcefd3c90aedbe9dd1c573e4c1ddbca8c74bf4fa664dd3b1a599ac9a66"}, + {file = "pyright-1.1.350.tar.gz", hash = "sha256:a8ba676de3a3737ea4d8590604da548d4498cc5ee9ee00b1a403c6db987916c6"}, +] + +[package.dependencies] +nodeenv = ">=1.6.0" + +[package.extras] +all = ["twine (>=3.4.1)"] +dev = ["twine (>=3.4.1)"] + [[package]] name = "pytest" version = "7.4.4" @@ -1555,4 +1515,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = ">=3.8,<4.0" -content-hash = "ce7a2165b76c51026fb021b33dbd6a8a2ab9341cb003499ca237a263f5cf1073" +content-hash = "fe845b55af387ffd5baf64801eb0389bec4a12c7e6d7384e731cf8715c70b860" diff --git a/pyproject.toml b/pyproject.toml index 471b161..2edaad0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,14 +13,16 @@ python = ">=3.8,<4.0" pydantic = "^2.6.4" httpx = "^0.27.0" lxml = "^5.1.0" +pyright = "1.1.350" [tool.poetry.group.dev.dependencies] pytest = "^7.2.0" -mypy = "^1.5.1" pre-commit = "^3.4.0" tox = "^4.11.1" rich = "^13.7.1" +[tool.pyright] +typeCheckingMode = "basic" [tool.poetry.group.docs.dependencies] mkdocs = "^1.4.2" diff --git a/tox.ini b/tox.ini index a44a21b..a856972 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,9 @@ [tox] skipsdist = true -envlist = py38, py39, py310, py311 +envlist = py39, py310, py311 [gh-actions] python = - 3.8: py38 3.9: py39 3.10: py310 3.11: py311 @@ -14,5 +13,5 @@ passenv = PYTHON_VERSION allowlist_externals = poetry commands = poetry install -v - pytest --doctest-modules tests --cov --cov-config=pyproject.toml --cov-report=xml - mypy + poetry run pytest tests + poetry run pyright fastexchange