Skip to content

Commit

Permalink
black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
freider committed Jan 26, 2024
1 parent ff56a4a commit 135f645
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 38 deletions.
12 changes: 4 additions & 8 deletions synchronicity/combined_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,10 @@ def __get__(self, instance, owner=None):


class AsyncAndBlockingContextManager(typing_extensions.Protocol[CTX]):
def __enter__(self) -> CTX:
...
def __enter__(self) -> CTX: ...

async def __aenter__(self) -> CTX:
...
async def __aenter__(self) -> CTX: ...

def __exit__(self, typ, value, tb):
...
def __exit__(self, typ, value, tb): ...

async def __aexit__(self, typ, value, tb):
...
async def __aexit__(self, typ, value, tb): ...
1 change: 1 addition & 0 deletions synchronicity/overload_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def foo(a: typing.Union[bool, int]) -> typing.Union[bool, float]:
# in the order they are declared
foo_overloads = get_overloads(foo)
"""

import contextlib
import typing
from unittest import mock
Expand Down
1 change: 1 addition & 0 deletions synchronicity/type_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
implementation types directly (but translated to blocking).
* Let synchronicity emit actual function bodies, to avoid runtime wrapping altogether
"""

import collections
import collections.abc
import contextlib
Expand Down
3 changes: 1 addition & 2 deletions test/async_wrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def bar():

def test_wrap_asynccontextmanager_annotations():
@async_wrap.asynccontextmanager # this would not work with contextlib.asynccontextmanager
async def foo() -> typing.AsyncGenerator[int, None]:
...
async def foo() -> typing.AsyncGenerator[int, None]: ...

assert foo.__annotations__["return"] == typing.AsyncContextManager[int]

Expand Down
3 changes: 1 addition & 2 deletions test/type_stub_helpers/e2e_example_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ async def gen(self) -> AsyncGenerator[int, None]:
yield 1

@staticmethod
def some_static(arg: str) -> float:
...
def some_static(arg: str) -> float: ...

@classmethod
def clone(cls, foo: "_Foo") -> "_Foo": # self ref
Expand Down
39 changes: 13 additions & 26 deletions test/type_stub_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@
from .type_stub_helpers import some_mod


def noop():
...
def noop(): ...


def arg_no_anno(arg1):
...
def arg_no_anno(arg1): ...


def scalar_args(arg1: str, arg2: int) -> float:
return 0


def generic_other_module_arg(arg: typing.List[some_mod.Foo]):
...
def generic_other_module_arg(arg: typing.List[some_mod.Foo]): ...


async def async_func() -> str:
Expand Down Expand Up @@ -154,8 +151,7 @@ def test_wrapped_function_with_new_annotations():
This test makes sure we do just that.
"""

def orig(arg: str):
...
def orig(arg: str): ...

@functools.wraps(orig)
def wrapper(extra_arg: int, *args, **kwargs):
Expand Down Expand Up @@ -206,12 +202,10 @@ def test_string_annotation():


class Forwarder:
def foo(self) -> typing.Optional["Forwardee"]:
...
def foo(self) -> typing.Optional["Forwardee"]: ...


class Forwardee:
...
class Forwardee: ...


def test_forward_ref():
Expand Down Expand Up @@ -271,8 +265,7 @@ def test_synchronicity_self_ref():

class _WithClassMethod:
@classmethod
def classy(cls):
...
def classy(cls): ...

async def meth(self, arg: bool) -> int:
return 0
Expand Down Expand Up @@ -306,8 +299,7 @@ async def aio(self, *args, **kwargs) -> int:
T = typing.TypeVar("T")


class MyGeneric(typing.Generic[T]):
...
class MyGeneric(typing.Generic[T]): ...


BlockingGeneric = synchronizer.create_blocking(typing.Generic, "BlockingGeneric", __name__)
Expand All @@ -320,16 +312,14 @@ class MyGeneric(typing.Generic[T]):

def test_custom_generic():
# TODO: build out this test a bit, as it currently creates an invalid stub (missing base types)
class Specific(MyGeneric[str]):
...
class Specific(MyGeneric[str]): ...

src = _class_source(Specific)
assert "class Specific(MyGeneric[str]):" in src


def test_synchronicity_generic_subclass():
class Specific(MyGeneric[str]):
...
class Specific(MyGeneric[str]): ...

assert Specific.__bases__ == (MyGeneric,)
assert Specific.__orig_bases__ == (MyGeneric[str],)
Expand All @@ -338,8 +328,7 @@ class Specific(MyGeneric[str]):
src = _class_source(BlockingSpecific)
assert "class BlockingSpecific(BlockingMyGeneric[str]):" in src

async def foo_impl(bar: MyGeneric[str]):
...
async def foo_impl(bar: MyGeneric[str]): ...

foo = synchronizer.create_blocking(foo_impl, "foo")
src = _function_source(foo)
Expand Down Expand Up @@ -390,12 +379,10 @@ def test_overloads_unwrapped_functions():
with overload_tracking.patched_overload():

@typing.overload
def _overloaded(arg: str) -> float:
...
def _overloaded(arg: str) -> float: ...

@typing.overload
def _overloaded(arg: int) -> int:
...
def _overloaded(arg: int) -> int: ...

def _overloaded(arg: typing.Union[str, int]):
if isinstance(arg, str):
Expand Down

0 comments on commit 135f645

Please sign in to comment.