Skip to content

Commit aa08341

Browse files
committed
Debug and typing
1 parent 987fb56 commit aa08341

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

nbviewer/_version.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import subprocess
1313
import sys
1414

15+
from typing import Dict
16+
1517

1618
def get_keywords():
1719
"""Get the keywords needed to look up the version information."""
@@ -48,7 +50,7 @@ class NotThisMethod(Exception):
4850
"""Exception raised if a method is not valid for the current scenario."""
4951

5052

51-
LONG_VERSION_PY = {}
53+
LONG_VERSION_PY: Dict[str, str] = {}
5254
HANDLERS = {}
5355

5456

nbviewer/providers/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from urllib.parse import urlencode
1818
from urllib.parse import urlparse
1919
from urllib.parse import urlunparse
20+
from functools import wraps
2021

2122
import statsd
2223
from nbformat import current_nbformat
@@ -529,7 +530,7 @@ def cached(method):
529530
This only handles getting from the cache, not writing to it.
530531
Writing to the cache must be handled in the decorated method.
531532
"""
532-
533+
@wraps(method)
533534
async def cached_method(self, *args, **kwargs):
534535
uri = self.request.path
535536
short_url = self.truncate(uri)

nbviewer/providers/github/handlers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,16 @@ async def get(self, user, repo, ref, path):
233233
# Account for possibility that GitHub API redirects us to get more accurate breadcrumbs
234234
# See: https://github.com/jupyter/nbviewer/issues/324
235235
example_file_url = contents[0]["html_url"]
236-
user, repo = re.match(
236+
match_group = re.match(
237237
r"^" + self.github_url + r"(?P<user>[^\/]+)/(?P<repo>[^\/]+)/.*",
238238
example_file_url,
239-
).group("user", "repo")
239+
)
240+
241+
if match_group is None:
242+
raise ValueError(
243+
f"Could not extract user/repo fromexample_file_url={example_file_url}"
244+
)
245+
user, repo = match_group.group("user", "repo")
240246

241247
base_url = "/github/{user}/{repo}/tree/{ref}".format(
242248
user=user, repo=repo, ref=ref

nbviewer/tests/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
from nbviewer.providers.github.client import AsyncGitHubClient
2424
from nbviewer.utils import url_path_join
2525

26+
from typing import Dict
27+
2628

2729
class NBViewerTestCase(TestCase):
2830
"""A base class for tests that need a running nbviewer server."""
2931

3032
port = 12341
3133

32-
environment_variables = {}
34+
environment_variables:Dict[str, str] = {}
3335

3436
def assertIn(self, observed, expected, *args, **kwargs):
3537
return super().assertIn(

nbviewer/tests/test_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class ElasticSearchTestCase(NBViewerTestCase):
8-
@skip
8+
@skip("unconditionally skip")
99
@classmethod
1010
def test_finish_notebook(self):
1111
pass

nbviewer/tests/test_json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010

1111
class JSONTestCase(TestCase):
12-
json = None
13-
schema = None
12+
json: str
13+
schema: str
1414

1515
def test_json(self):
1616
if not self.json:

0 commit comments

Comments
 (0)