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 1 commit
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
Prev Previous commit
Removes "removesuffix" function
  • Loading branch information
JasonWeill committed May 17, 2023
commit 801f635be51bbf6311e31a217f2bd4f81ba9ad0f
8 changes: 4 additions & 4 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,8 +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}`";

initial_comma = r'^, '
return re.sub(initial_comma, '', output)
# 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 @@ -368,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