-
Notifications
You must be signed in to change notification settings - Fork 3
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
Sourcery refactored master branch #8
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,11 +59,10 @@ def __ror__(self, other: Mapping | None): | |
|
||
def __ior__(self, other: MutableMapping | None): | ||
if other is not None and other is not self: | ||
if isinstance(other, ChainContext): | ||
self.primary_map.maps[0:0] = other.primary_map | ||
self.fallback_map.maps[0:0] = other.fallback_map | ||
else: | ||
if not isinstance(other, ChainContext): | ||
return super().__ior__(other) | ||
self.primary_map.maps[:0] = other.primary_map | ||
self.fallback_map.maps[:0] = other.fallback_map | ||
return self | ||
|
||
def __repr__(self): | ||
|
@@ -218,10 +217,7 @@ async def _arun(self, context, /, complete=None): | |
await self._apply_async_post_processes(context) | ||
|
||
def next(self, chain: AbstractChain): | ||
if isinstance(chain, Chain): | ||
return Chain(self, *chain) | ||
else: | ||
return Chain(self, chain) | ||
return Chain(self, *chain) if isinstance(chain, Chain) else Chain(self, chain) | ||
Comment on lines
-221
to
+220
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def __add__(self, chain: AbstractChain): | ||
return self.next(chain) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,18 +8,13 @@ | |
if version_info >= (3, 11): | ||
from typing import NotRequired, TypedDict | ||
|
||
class Message(TypedDict): # type: ignore | ||
role: Role | ||
content: str | ||
name: NotRequired[str] | ||
|
||
else: | ||
from typing_extensions import NotRequired, TypedDict | ||
|
||
class Message(TypedDict): | ||
role: Role | ||
content: str | ||
name: NotRequired[str] | ||
class Message(TypedDict): # type: ignore | ||
role: Role | ||
content: str | ||
name: NotRequired[str] | ||
Comment on lines
-11
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong. These changes are introducing new static-type-checking failures. |
||
|
||
|
||
class MessageBuilder: | ||
|
@@ -84,8 +79,7 @@ def parse_chat_markup(text: str) -> list[Message]: | |
buffer = [] | ||
|
||
for line in text.splitlines(): | ||
match = is_message_start.match(line) | ||
if match: | ||
if match := is_message_start.match(line): | ||
Comment on lines
-87
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
role, name = match.group(1), match.group(2) | ||
|
||
if current_message: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,13 +59,13 @@ def _on_special_token(self, token, sync: bool): | |
else: | ||
op = inner.split(" ", 1)[0] | ||
|
||
if op == "if" or op == "for" or op == "while": | ||
if op in ["if", "for", "while"]: | ||
self._ops_stack.append(op) | ||
self._flush() | ||
self._builder.add_line(f"{inner}:") | ||
self._builder.indent() | ||
|
||
elif op == "else" or op == "elif": | ||
elif op in ["else", "elif"]: | ||
Comment on lines
-62
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
self._flush() | ||
self._builder.dedent() | ||
self._builder.add_line(f"{inner}:") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
ChainContext.__ior__
refactored with the following changes:swap-if-else-branches
)remove-unnecessary-else
)remove-redundant-slice-index
)