Skip to content

Commit

Permalink
Avoids using str.removeprefix and str.removesuffix (jupyterlab#169)
Browse files Browse the repository at this point in the history
* Replaces "removeprefix" with regex

* Removes "removesuffix" function
  • Loading branch information
JasonWeill authored May 17, 2023
1 parent df6925e commit 8383f25
Showing 1 changed file with 4 additions and 3 deletions.
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

0 comments on commit 8383f25

Please sign in to comment.