Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update syntax for existing type annotations #5298

Merged
merged 2 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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