Skip to content

Commit

Permalink
Add types and docstrings.
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardBetts committed Oct 2, 2023
1 parent 01dc25a commit 2a5ace3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 11 additions & 4 deletions matcher/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from sqlalchemy.schema import Column, ForeignKey, ForeignKeyConstraint, UniqueConstraint
from sqlalchemy.sql.expression import false, or_, true
from sqlalchemy.types import JSON, BigInteger, Boolean, DateTime, Float, Integer, String
from werkzeug.wrappers.response import Response

from . import (
default_change_comments,
Expand Down Expand Up @@ -841,12 +842,16 @@ def get_oql(self, buildings_special=False):
def candidates_url(self, **kwargs):
return self.place_url("candidates", **kwargs)

def place_url(self, endpoint, **kwargs):
def place_url(self, endpoint: str, **kwargs) -> str:
"""Flask URL for this place."""
return url_for(endpoint, osm_type=self.osm_type, osm_id=self.osm_id, **kwargs)

def browse_url(self):
def browse_url(self) -> str | None:
"""Browse URL if place has associated wikidata item."""
if self.wikidata:
return url_for("browse_page", item_id=self.wikidata_item_id)
else:
return None

def next_state_url(self):
return (
Expand All @@ -855,13 +860,15 @@ def next_state_url(self):
else self.matcher_progress_url()
)

def matcher_progress_url(self):
def matcher_progress_url(self) -> str:
"""Matcher progress URL."""
return self.place_url("matcher.matcher_progress")

def matcher_done_url(self, start):
return self.place_url("matcher.matcher_done", start=start)

def redirect_to_matcher(self):
def redirect_to_matcher(self) -> Response:
"""Redirect to matcher page for this place."""
return redirect(self.matcher_progress_url())

def item_list(self):
Expand Down
5 changes: 3 additions & 2 deletions matcher/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -1584,9 +1584,10 @@ def browse_page(item_id: int) -> str:


@app.route("/matcher/Q<int:item_id>")
def matcher_wikidata(item_id):
def get_search_string(qid):
def matcher_wikidata(item_id: int) -> Response:
def get_search_string(qid: str) -> str:
entity = wikidata_api.get_entity(qid)
assert entity is not None
return browse.qid_to_search_string(qid, entity)

qid = "Q{}".format(item_id)
Expand Down

0 comments on commit 2a5ace3

Please sign in to comment.