Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(next => main): release 1.16.0 #195

Merged
merged 8 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.15.0"
".": "1.16.0"
}
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

## 1.16.0 (2023-09-11)

Full Changelog: [v1.15.0...v1.16.0](https://github.com/Modern-Treasury/modern-treasury-python/compare/v1.15.0...v1.16.0)

### Features

* fixes tests where an array has to have unique enum values ([#196](https://github.com/Modern-Treasury/modern-treasury-python/issues/196)) ([1e582ba](https://github.com/Modern-Treasury/modern-treasury-python/commit/1e582baa5782a61f757d4a9060f15209ba14c081))


### Bug Fixes

* **client:** properly handle optional file params ([#194](https://github.com/Modern-Treasury/modern-treasury-python/issues/194)) ([08db5c4](https://github.com/Modern-Treasury/modern-treasury-python/commit/08db5c435d42eb86bf7e7dc1f6c9239164c2cdef))


### Chores

* **internal:** minor update ([#198](https://github.com/Modern-Treasury/modern-treasury-python/issues/198)) ([2372dd7](https://github.com/Modern-Treasury/modern-treasury-python/commit/2372dd7dfcbb152e8b08bed89c99eeb16247fbd0))
* **internal:** update base client ([#197](https://github.com/Modern-Treasury/modern-treasury-python/issues/197)) ([f8969c8](https://github.com/Modern-Treasury/modern-treasury-python/commit/f8969c8f7f21d629864e08b33986cb774a2657b5))
* **internal:** update pyright ([#201](https://github.com/Modern-Treasury/modern-treasury-python/issues/201)) ([087470d](https://github.com/Modern-Treasury/modern-treasury-python/commit/087470dbeda6205a6012d3e8ddfa3b03d74ad7b2))
* **internal:** updates ([#200](https://github.com/Modern-Treasury/modern-treasury-python/issues/200)) ([5c940e0](https://github.com/Modern-Treasury/modern-treasury-python/commit/5c940e01787e6218769823908cf20c6627b645e7))


### Documentation

* **readme:** add link to api.md ([#199](https://github.com/Modern-Treasury/modern-treasury-python/issues/199)) ([bd499a1](https://github.com/Modern-Treasury/modern-treasury-python/commit/bd499a10002e3ae158e70f6221b94eacb9472d1d))

## 1.15.0 (2023-09-01)

Full Changelog: [v1.14.0...v1.15.0](https://github.com/Modern-Treasury/modern-treasury-python/compare/v1.14.0...v1.15.0)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pip install modern-treasury

## Usage

The full API of this library can be found in [api.md](https://www.github.com/Modern-Treasury/modern-treasury-python/blob/main/api.md).

```python
from modern_treasury import ModernTreasury

Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

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

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "modern-treasury"
version = "1.15.0"
version = "1.16.0"
description = "Client library for the Modern Treasury API"
readme = "README.md"
authors = ["Modern Treasury <sdk-feedback@moderntreasury.com>"]
Expand All @@ -21,7 +21,7 @@ distro = ">= 1.7.0, < 2"


[tool.poetry.group.dev.dependencies]
pyright = "1.1.318"
pyright = "1.1.326"
mypy = "1.4.1"
black = "23.3.0"
respx = "0.19.2"
Expand All @@ -34,6 +34,7 @@ nox = "^2023.4.22"
nox-poetry = "^1.0.3"



[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Expand Down
20 changes: 17 additions & 3 deletions src/modern_treasury/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
overload,
)
from functools import lru_cache
from typing_extensions import Literal, get_origin
from typing_extensions import Literal, get_args, get_origin

import anyio
import httpx
Expand Down Expand Up @@ -458,6 +458,14 @@ def _serialize_multipartform(self, data: Mapping[object, object]) -> dict[str, o
serialized[key] = value
return serialized

def _extract_stream_chunk_type(self, stream_cls: type) -> type:
args = get_args(stream_cls)
if not args:
raise TypeError(
f"Expected stream_cls to have been given a generic type argument, e.g. Stream[Foo] but received {stream_cls}",
)
return cast(type, args[0])

def _process_response(
self,
*,
Expand Down Expand Up @@ -793,7 +801,10 @@ def _request(
raise APIConnectionError(request=request) from err

if stream:
stream_cls = stream_cls or cast("type[_StreamT] | None", self._default_stream_cls)
if stream_cls:
return stream_cls(cast_to=self._extract_stream_chunk_type(stream_cls), response=response, client=self)

stream_cls = cast("type[_StreamT] | None", self._default_stream_cls)
if stream_cls is None:
raise MissingStreamClassError()
return stream_cls(cast_to=cast_to, response=response, client=self)
Expand Down Expand Up @@ -1156,7 +1167,10 @@ async def _request(
raise APIConnectionError(request=request) from err

if stream:
stream_cls = stream_cls or cast("type[_AsyncStreamT] | None", self._default_stream_cls)
if stream_cls:
return stream_cls(cast_to=self._extract_stream_chunk_type(stream_cls), response=response, client=self)

stream_cls = cast("type[_AsyncStreamT] | None", self._default_stream_cls)
if stream_cls is None:
raise MissingStreamClassError()
return stream_cls(cast_to=cast_to, response=response, client=self)
Expand Down
12 changes: 9 additions & 3 deletions src/modern_treasury/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ def model_copy(model: _ModelT) -> _ModelT:
return model.copy() # type: ignore


def model_json(model: pydantic.BaseModel) -> str:
def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
if PYDANTIC_V2:
return model.model_dump_json()
return model.json() # type: ignore
return model.model_dump_json(indent=indent)
return model.json(indent=indent) # type: ignore


def model_dump(model: pydantic.BaseModel) -> dict[str, Any]:
Expand All @@ -132,6 +132,12 @@ def model_dump(model: pydantic.BaseModel) -> dict[str, Any]:
return cast("dict[str, Any]", model.dict()) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]


def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
if PYDANTIC_V2:
return model.model_validate(data)
return model.parse_obj(data) # pyright: ignore[reportDeprecated]


# generic models
if TYPE_CHECKING:

Expand Down
2 changes: 1 addition & 1 deletion src/modern_treasury/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def validate_type(*, type_: type[_T], value: object) -> _T:
if inspect.isclass(type_) and issubclass(type_, pydantic.BaseModel):
return cast(_T, parse_obj(type_, value))

return _validate_non_model_type(type_=type_, value=value)
return cast(_T, _validate_non_model_type(type_=type_, value=value))


# our use of subclasssing here causes weirdness for type checkers,
Expand Down
8 changes: 8 additions & 0 deletions src/modern_treasury/_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

import time
import asyncio
from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand All @@ -20,6 +22,9 @@ def __init__(self, client: ModernTreasury) -> None:
self._delete = client.delete
self._get_api_list = client.get_api_list

def _sleep(self, seconds: float) -> None:
time.sleep(seconds)


class AsyncAPIResource:
_client: AsyncModernTreasury
Expand All @@ -32,3 +37,6 @@ def __init__(self, client: AsyncModernTreasury) -> None:
self._put = client.put
self._delete = client.delete
self._get_api_list = client.get_api_list

async def _sleep(self, seconds: float) -> None:
await asyncio.sleep(seconds)
3 changes: 2 additions & 1 deletion src/modern_treasury/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
_T = TypeVar("_T")

# Approximates httpx internal ProxiesTypes and RequestFiles types
ProxiesTypes = Union[str, Proxy, Dict[str, Union[None, str, Proxy]]]
ProxiesDict = Dict[str, Union[None, str, Proxy]]
ProxiesTypes = Union[str, Proxy, ProxiesDict]
FileContent = Union[IO[bytes], bytes]
FileTypes = Union[
# file (or bytes)
Expand Down
1 change: 1 addition & 0 deletions src/modern_treasury/_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ._utils import flatten as flatten
from ._utils import is_dict as is_dict
from ._utils import is_list as is_list
from ._utils import is_given as is_given
from ._utils import is_mapping as is_mapping
from ._utils import parse_date as parse_date
from ._utils import coerce_float as coerce_float
Expand Down
11 changes: 9 additions & 2 deletions src/modern_treasury/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path
from typing_extensions import Required, Annotated, TypeGuard, get_args, get_origin

from .._types import NotGiven, FileTypes
from .._types import NotGiven, FileTypes, NotGivenOr
from .._compat import is_union as _is_union
from .._compat import parse_date as parse_date
from .._compat import parse_datetime as parse_datetime
Expand Down Expand Up @@ -38,12 +38,15 @@ def _extract_items(
path: Sequence[str],
*,
index: int,
# TODO: rename
flattened_key: str | None,
) -> list[tuple[str, FileTypes]]:
try:
key = path[index]
except IndexError:
if isinstance(obj, NotGiven):
# no value was provided - we can safely ignore
return []

# We have exhausted the path, return the entry we found.
if not isinstance(obj, bytes) and not isinstance(obj, tuple):
raise RuntimeError(
Expand Down Expand Up @@ -97,6 +100,10 @@ def _extract_items(
return []


def is_given(obj: NotGivenOr[_T]) -> TypeGuard[_T]:
return not isinstance(obj, NotGiven)


# Type safe methods for narrowing types with TypeVars.
# The default narrowing for isinstance(obj, dict) is dict[unknown, unknown],
# however this cause Pyright to rightfully report errors. As we know we don't
Expand Down
2 changes: 1 addition & 1 deletion src/modern_treasury/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless.

__title__ = "modern_treasury"
__version__ = "1.15.0" # x-release-please-version
__version__ = "1.16.0" # x-release-please-version
4 changes: 2 additions & 2 deletions tests/api_resources/test_counterparties.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def test_method_collect_account_with_all_params(self, client: ModernTreasury) ->
"string",
direction="credit",
custom_redirect="https://example.com",
fields=["name", "name", "name"],
fields=["name", "nameOnAccount", "taxpayerIdentifier"],
send_email=True,
)
assert_matches_type(CounterpartyCollectAccountResponse, counterparty, path=["response"])
Expand Down Expand Up @@ -710,7 +710,7 @@ async def test_method_collect_account_with_all_params(self, client: AsyncModernT
"string",
direction="credit",
custom_redirect="https://example.com",
fields=["name", "name", "name"],
fields=["name", "nameOnAccount", "taxpayerIdentifier"],
send_email=True,
)
assert_matches_type(CounterpartyCollectAccountResponse, counterparty, path=["response"])
4 changes: 2 additions & 2 deletions tests/api_resources/test_external_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def test_method_complete_verification(self, client: ModernTreasury) -> None:
def test_method_complete_verification_with_all_params(self, client: ModernTreasury) -> None:
external_account = client.external_accounts.complete_verification(
"string",
amounts=[0, 0],
amounts=[2, 4],
)
assert_matches_type(ExternalAccount, external_account, path=["response"])

Expand Down Expand Up @@ -381,7 +381,7 @@ async def test_method_complete_verification(self, client: AsyncModernTreasury) -
async def test_method_complete_verification_with_all_params(self, client: AsyncModernTreasury) -> None:
external_account = await client.external_accounts.complete_verification(
"string",
amounts=[0, 0],
amounts=[2, 4],
)
assert_matches_type(ExternalAccount, external_account, path=["response"])

Expand Down