Skip to content
Open
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
15 changes: 7 additions & 8 deletions marimo/_cli/file_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ def is_gist_src(url: str) -> bool:
if not is_url(url):
return False

hostname = urllib.parse.urlparse(url).hostname
if (
hostname != "gist.github.com"
and hostname != "gist.githubusercontent.com"
):
return False
return True
# Use urlparse only once and cache the result, avoid attribute access if possible
parsed = urllib.parse.urlparse(url)
hostname = parsed.hostname
# Use a set for O(1) membership tests
return hostname in {"gist.github.com", "gist.githubusercontent.com"}


def get_gist_src_url(url: str) -> str:
Expand Down Expand Up @@ -226,7 +224,8 @@ def read(self, name: str) -> tuple[str, str]:

class GistSourceReader(FileReader):
def can_read(self, name: str) -> bool:
return is_gist_src(name) or is_gist_src(name)
# Avoid double computation by only calling is_gist_src once
return is_gist_src(name)

def read(self, name: str) -> tuple[str, str]:
url = get_gist_src_url(name)
Expand Down