Skip to content

Commit

Permalink
Add support for python 3.9~3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
ManiMozaffar committed Mar 23, 2024
1 parent 054f70e commit 185ff78
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 79 deletions.
5 changes: 5 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VIRTUAL_ENV="$(pwd)/.venv"
PATH=$VIRTUAL_ENV/bin:$PATH
export VIRTUAL_ENV
export PATH
export POETRY_ACTIVE=1
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,7 +57,6 @@ jobs:
- name: Test with tox
run: tox


check-docs:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions examples/basic1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from decimal import Decimal

from fastexchange.currency import EURCurrency, USDCurrency
Expand Down
1 change: 1 addition & 0 deletions examples/basic2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
import asyncio
from decimal import Decimal

Expand Down
2 changes: 2 additions & 0 deletions examples/basic3.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# type: ignore

import asyncio

from rich import print
Expand Down
3 changes: 2 additions & 1 deletion fastexchange/converter/base_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abc import ABC, abstractmethod
from typing import Union

from typing_extensions import TypeVar

Expand All @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions fastexchange/converter/mappings.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
10 changes: 5 additions & 5 deletions fastexchange/crypto/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"""
Expand Down
4 changes: 3 additions & 1 deletion fastexchange/crypto/usdt.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
3 changes: 2 additions & 1 deletion fastexchange/currency.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 3 additions & 3 deletions fastexchange/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
78 changes: 19 additions & 59 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 3 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit 185ff78

Please sign in to comment.