Skip to content

Commit

Permalink
Merge pull request #5298 from pierwill/pierwill-type-syntax-2
Browse files Browse the repository at this point in the history
Update syntax for existing type annotations
  • Loading branch information
kushaldas committed Jun 9, 2020
2 parents 309f17e + 0a3c60d commit 2c65008
Show file tree
Hide file tree
Showing 8 changed files with 101 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
14 changes: 6 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,16 @@ 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 +128,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 2c65008

Please sign in to comment.