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

Avoids using str.removeprefix and str.removesuffix #169

Merged
merged 2 commits into from
May 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/jupyter-ai-magics/jupyter_ai_magics/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Base64Image:
def __init__(self, mimeData, metadata):
mimeDataParts = mimeData.split(',')
self.data = base64.b64decode(mimeDataParts[1]);
self.mimeType = mimeDataParts[0].removesuffix(';base64')
self.mimeType = re.sub(r';base64$', '', mimeDataParts[0])
self.metadata = metadata

def _repr_mimebundle_(self, include=None, exclude=None):
Expand Down Expand Up @@ -146,7 +146,8 @@ def _ai_inline_list_models_for_provider(self, provider_id, Provider):
for model_id in Provider.models:
output += f", `{provider_id}:{model_id}`";

return output.removeprefix(', ')
# Remove initial comma
return re.sub(r'^, ', '', output)

# Is the required environment variable set?
def _ai_env_status_for_provider_markdown(self, provider_id):
Expand Down Expand Up @@ -367,7 +368,7 @@ def ai(self, line, cell=None):
# Strip a leading language indicator and trailing triple-backticks
lang_indicator = r'^```[a-zA-Z0-9]*\n'
output = re.sub(lang_indicator, '', output)
output = output.removesuffix('\n```')
output = re.sub(r'\n```$', '', output)
new_cell_payload = dict(
source='set_next_input',
text=output,
Expand Down