Skip to content

Commit

Permalink
Update syntax for existing type annotations
Browse files Browse the repository at this point in the history
Uses syntax described in PEP484.
  • Loading branch information
pierwill committed Jun 5, 2020
1 parent 1e39cd2 commit f4647f5
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 130 deletions.
3 changes: 1 addition & 2 deletions securedrop/crypto_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ def do_runtime_tests(self):
if not rm.check_secure_delete_capability():
raise AssertionError("Secure file deletion is not possible.")

def get_wordlist(self, locale):
# type: (Text) -> List[str]
def get_wordlist(self, locale: Text) -> List[str]:
"""" Ensure the wordlist for the desired locale is read and available
in the words global variable. If there is no wordlist for the
desired local, fallback to the default english wordlist.
Expand Down
12 changes: 4 additions & 8 deletions securedrop/journalist_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
_insecure_views = ['main.login', 'main.select_logo', 'static']


def create_app(config):
# type: (SDConfig) -> Flask
def create_app(config: SDConfig) -> Flask:
app = Flask(__name__,
template_folder=config.JOURNALIST_TEMPLATES_DIR,
static_folder=path.join(config.SECUREDROP_ROOT, 'static'))
Expand Down Expand Up @@ -82,16 +81,14 @@ def create_app(config):
)

@app.errorhandler(CSRFError)
def handle_csrf_error(e):
# type: (CSRFError) -> Response
def handle_csrf_error(e: CSRFError) -> Response:
# render the message first to ensure it's localized.
msg = gettext('You have been logged out due to inactivity')
session.clear()
flash(msg, 'error')
return redirect(url_for('main.login'))

def _handle_http_exception(error):
# type: (HTTPException) -> Tuple[Union[Response, str], Optional[int]]
def _handle_http_exception(error: HTTPException) -> Tuple[Union[Response, str], Optional[int]]:
# Workaround for no blueprint-level 404/5 error handlers, see:
# https://github.com/pallets/flask/issues/503#issuecomment-71383286
handler = list(app.error_handler_spec['api'][error.code].values())[0]
Expand Down Expand Up @@ -129,8 +126,7 @@ def load_instance_config():
app.instance_config = InstanceConfig.get_current()

@app.before_request
def setup_g():
# type: () -> Optional[Response]
def setup_g() -> Optional[Response]:
"""Store commonly used values in Flask's special g object"""
if 'expires' in session and datetime.utcnow() >= session['expires']:
session.clear()
Expand Down
6 changes: 2 additions & 4 deletions securedrop/journalist_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
from sdconfig import SDConfig # noqa: F401


def logged_in():
# type: () -> bool
def logged_in() -> bool:
# When a user is logged in, we push their user ID (database primary key)
# into the session. setup_g checks for this value, and if it finds it,
# stores a reference to the user's Journalist object in g.
Expand Down Expand Up @@ -255,8 +254,7 @@ def col_delete(cols_selected):
return redirect(url_for('main.index'))


def make_password(config):
# type: (SDConfig) -> str
def make_password(config: SDConfig) -> str:
while True:
password = current_app.crypto_util.genrandomid(
7,
Expand Down

0 comments on commit f4647f5

Please sign in to comment.