Skip to content

Commit

Permalink
Merge pull request #7 from YosysHQ/reformat
Browse files Browse the repository at this point in the history
make reformat: Improved type signature formatting
  • Loading branch information
jix authored Jan 29, 2024
2 parents b046db4 + 33b5c35 commit e2f422c
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 82 deletions.
12 changes: 4 additions & 8 deletions src/yosys_mau/config_parser/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,25 +278,21 @@ def __set_name__(self, owner: object, name: str) -> None:
owner.__register_option_parser__(self)

@typing.overload
def __get__(self, instance: ConfigOptions, owner: type[ConfigOptions]) -> T:
...
def __get__(self, instance: ConfigOptions, owner: type[ConfigOptions]) -> T: ...

@typing.overload
def __get__(self, instance: object, owner: object = None) -> Self:
...
def __get__(self, instance: object, owner: object = None) -> Self: ...

def __get__(self, instance: object, owner: object = None) -> T | Self:
if isinstance(instance, ConfigOptions):
return instance.__option_parser_result__(self)
return self

@typing.overload
def __set__(self, instance: object, value: Self) -> None:
...
def __set__(self, instance: object, value: Self) -> None: ...

@typing.overload
def __set__(self, instance: ConfigOptions, value: T) -> None:
...
def __set__(self, instance: ConfigOptions, value: T) -> None: ...

def __set__(self, instance: Any, value: Self | T) -> None:
if isinstance(instance, ConfigOptions):
Expand Down
33 changes: 11 additions & 22 deletions src/yosys_mau/config_parser/_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ def matching_sections(
arguments: None | bool = None,
all_sections: bool = False,
mark_as_processed: bool = True,
) -> list[ConfigSection]:
...
) -> list[ConfigSection]: ...

@typing.overload
def matching_sections(
Expand All @@ -255,8 +254,7 @@ def matching_sections(
unique: bool = False,
arguments: ValueParser[A],
mark_as_processed: bool = True,
) -> dict[A, list[ConfigSection]]:
...
) -> dict[A, list[ConfigSection]]: ...

def matching_sections(
self,
Expand Down Expand Up @@ -377,25 +375,21 @@ def __set_name__(self, owner: object, name: str) -> None:
owner.__register_section_parser__(self)

@typing.overload
def __get__(self, instance: ConfigParser, owner: type[ConfigParser]) -> T:
...
def __get__(self, instance: ConfigParser, owner: type[ConfigParser]) -> T: ...

@typing.overload
def __get__(self, instance: object, owner: object = None) -> Self:
...
def __get__(self, instance: object, owner: object = None) -> Self: ...

def __get__(self, instance: object, owner: object = None) -> T | Self:
if isinstance(instance, ConfigParser):
return instance.__section_parser_result__(self)
return self

@typing.overload
def __set__(self, instance: object, value: Self) -> None:
...
def __set__(self, instance: object, value: Self) -> None: ...

@typing.overload
def __set__(self, instance: ConfigParser, value: T) -> None:
...
def __set__(self, instance: ConfigParser, value: T) -> None: ...

def __set__(self, instance: Any, value: Self | T) -> None:
if isinstance(instance, ConfigParser):
Expand Down Expand Up @@ -462,12 +456,10 @@ def result(self, value: T) -> None:
self._result = value

@typing.overload
def with_arguments(self, value_parser: ValueParser[A]) -> ArgSection[A, T]:
...
def with_arguments(self, value_parser: ValueParser[A]) -> ArgSection[A, T]: ...

@typing.overload
def with_arguments(self, value_parser: None = None) -> ArgSection[str, T]:
...
def with_arguments(self, value_parser: None = None) -> ArgSection[str, T]: ...

def with_arguments(self, value_parser: ValueParser[Any] | None = None) -> ArgSection[Any, T]:
"""Wraps this section parser in an `ArgSection` parser."""
Expand Down Expand Up @@ -545,18 +537,15 @@ def __new__(
cls,
content_parser: SectionContentsParser[T] | Callable[[A], SectionContentsParser[T]],
argument_parser: ValueParser[A],
) -> ArgSection[A, T]:
...
) -> ArgSection[A, T]: ...

@typing.overload
def __new__(
cls,
content_parser: SectionContentsParser[T] | Callable[[str], SectionContentsParser[T]],
) -> ArgSection[str, T]:
...
) -> ArgSection[str, T]: ...

def __new__(cls, *args: Any, **kwargs: Any) -> ArgSection[Any, T]:
...
def __new__(cls, *args: Any, **kwargs: Any) -> ArgSection[Any, T]: ...

def parse(self) -> None:
sections = self.matching_sections(mark_as_processed=False, arguments=self.arguments_parser)
Expand Down
15 changes: 5 additions & 10 deletions src/yosys_mau/source_str/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,16 +442,13 @@ def __len__(self) -> int:
return self.len

@typing.overload
def _index(self, index: int, default: int | None) -> int:
...
def _index(self, index: int, default: int | None) -> int: ...

@typing.overload
def _index(self, index: int | None, default: int) -> int:
...
def _index(self, index: int | None, default: int) -> int: ...

@typing.overload
def _index(self, index: int | None, default: None) -> int | None:
...
def _index(self, index: int | None, default: None) -> int | None: ...

def _index(self, index: int | None, default: int | None) -> int | None:
if index is None:
Expand Down Expand Up @@ -512,12 +509,10 @@ def _bisect_ending_at(self, at: int | None) -> int:
return lo

@typing.overload
def __add__(self, other: SourceMap) -> SourceMap:
...
def __add__(self, other: SourceMap) -> SourceMap: ...

@typing.overload
def __add__(self, other: SourceSpans) -> SourceSpans:
...
def __add__(self, other: SourceSpans) -> SourceSpans: ...

def __add__(self, other: SourceSpans) -> SourceSpans:
if not isinstance(other, SourceMap):
Expand Down
36 changes: 12 additions & 24 deletions src/yosys_mau/source_str/re.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,10 @@ def end(self, group: int | str = 0) -> int:
return self.wrapped.end(group)

@overload
def group(self, group: Literal[0] = 0, /) -> str:
...
def group(self, group: Literal[0] = 0, /) -> str: ...

@overload
def group(self, group: str | int, /) -> str | None:
...
def group(self, group: str | int, /) -> str | None: ...

@overload
def group(
Expand All @@ -262,8 +260,7 @@ def group(
group2: str | int,
/,
*groups: str | int,
) -> tuple[str | None, ...]:
...
) -> tuple[str | None, ...]: ...

def group(self, *groups: str | int) -> str | tuple[str | None, ...] | None:
"""Source tracking wrapper for :external:meth:`re.Match.group`."""
Expand All @@ -274,29 +271,24 @@ def group(self, *groups: str | int) -> str | tuple[str | None, ...] | None:
return tuple(self._group(group) for group in groups)

@overload
def __getitem__(self, group: Literal[0]) -> str:
...
def __getitem__(self, group: Literal[0]) -> str: ...

@overload
def __getitem__(self, group: int | str) -> str | None:
...
def __getitem__(self, group: int | str) -> str | None: ...

def __getitem__(self, group: int | str) -> str | None:
"""Source tracking wrapper for :external:meth:`re.Match.__getitem__`."""
group_str = self._group(group)
return group_str

@overload
def _group(self, group: Literal[0], default: Any = None) -> str:
...
def _group(self, group: Literal[0], default: Any = None) -> str: ...

@overload
def _group(self, group: int | str, default: _T) -> str | _T:
...
def _group(self, group: int | str, default: _T) -> str | _T: ...

@overload
def _group(self, group: int | str) -> str | None:
...
def _group(self, group: int | str) -> str | None: ...

def _group(self, group: int | str, default: Any = None) -> Any:
if group == 0:
Expand All @@ -307,24 +299,20 @@ def _group(self, group: int | str, default: Any = None) -> Any:
return self.string[span[0] : span[1]]

@overload
def groups(self) -> tuple[str | None, ...]:
...
def groups(self) -> tuple[str | None, ...]: ...

@overload
def groups(self, default: _T) -> tuple[str | _T, ...]:
...
def groups(self, default: _T) -> tuple[str | _T, ...]: ...

def groups(self, default: Any = None) -> tuple[Any, ...]:
"""Source tracking wrapper for :external:meth:`re.Match.groups`."""
return tuple(self._group(group, default) for group in range(1, 1 + self.wrapped.re.groups))

@overload
def groupdict(self) -> dict[str, str | None]:
...
def groupdict(self) -> dict[str, str | None]: ...

@overload
def groupdict(self, default: _T) -> dict[str, str | _T]:
...
def groupdict(self, default: _T) -> dict[str, str | _T]: ...

def groupdict(self, default: Any = None) -> dict[str, Any]:
"""Source tracking wrapper for :external:meth:`re.Match.groupdict`."""
Expand Down
1 change: 1 addition & 0 deletions src/yosys_mau/source_str/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
The API for error reporting hasn't been fully designed yet and is likely to change.
"""

from __future__ import annotations

from collections import defaultdict
Expand Down
12 changes: 6 additions & 6 deletions src/yosys_mau/task_loop/_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,13 @@ def __str__(self) -> str:

def __init__(
self,
on_run: Callable[[Self], Awaitable[None] | None]
| Callable[[], Awaitable[None] | None]
| None = None,
on_run: (
Callable[[Self], Awaitable[None] | None] | Callable[[], Awaitable[None] | None] | None
) = None,
*,
on_prepare: Callable[[Self], Awaitable[None] | None]
| Callable[[], Awaitable[None] | None]
| None = None,
on_prepare: (
Callable[[Self], Awaitable[None] | None] | Callable[[], Awaitable[None] | None] | None
) = None,
name: str | None = None,
):
"""The constructor creates a new task as child task of the current task and schedule it to
Expand Down
6 changes: 2 additions & 4 deletions src/yosys_mau/task_loop/job_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,9 @@ def process_job_server_environment() -> None:


class Scheduler(typing.Protocol):
def __return_lease__(self) -> None:
...
def __return_lease__(self) -> None: ...

def request_lease(self) -> Lease:
...
def request_lease(self) -> Lease: ...


class Lease:
Expand Down
14 changes: 6 additions & 8 deletions src/yosys_mau/task_loop/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ def log_warning(*args: Any, cls: type[LogEvent] = LogEvent) -> LogEvent:
@overload
def log_error(
*args: Any, cls: type[LogEvent] = LogEvent, raise_error: Literal[True] = True
) -> NoReturn:
...
) -> NoReturn: ...


@overload
def log_error(*args: Any, cls: type[LogEvent] = LogEvent, raise_error: Literal[False]) -> LogEvent:
...
def log_error(
*args: Any, cls: type[LogEvent] = LogEvent, raise_error: Literal[False]
) -> LogEvent: ...


def log_error(*args: Any, cls: type[LogEvent] = LogEvent, raise_error: bool = True) -> LogEvent:
Expand All @@ -225,13 +225,11 @@ def log_error(*args: Any, cls: type[LogEvent] = LogEvent, raise_error: bool = Tr


@overload
def log_exception(exception: BaseException, raise_error: Literal[True] = True) -> NoReturn:
...
def log_exception(exception: BaseException, raise_error: Literal[True] = True) -> NoReturn: ...


@overload
def log_exception(exception: BaseException, raise_error: Literal[False]) -> LoggedError:
...
def log_exception(exception: BaseException, raise_error: Literal[False]) -> LoggedError: ...


def log_exception(exception: BaseException, raise_error: bool = True) -> LoggedError:
Expand Down

0 comments on commit e2f422c

Please sign in to comment.