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

Sourcery refactored master branch #8

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 4 additions & 8 deletions python/promplate/chain/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines -62 to +65
Copy link
Author

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:

return self

def __repr__(self):
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Node.next refactored with the following changes:


def __add__(self, chain: AbstractChain):
return self.next(chain)
Expand Down
16 changes: 5 additions & 11 deletions python/promplate/prompt/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 11-22 refactored with the following changes:

Copy link
Member

@CNSeniorious000 CNSeniorious000 Oct 31, 2023

Choose a reason for hiding this comment

The 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:
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function parse_chat_markup refactored with the following changes:

role, name = match.group(1), match.group(2)

if current_message:
Expand Down
4 changes: 2 additions & 2 deletions python/promplate/prompt/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TemplateCore._on_special_token refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator [×2] (merge-comparisons)

self._flush()
self._builder.dedent()
self._builder.add_line(f"{inner}:")
Expand Down
Loading