Skip to content

Commit 302b895

Browse files
committed
type annotations: use string literals (PEP 0484 forward references)
Workaround for: pylint-dev/pylint#3285
1 parent a5218db commit 302b895

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

securedrop/crypto_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def do_runtime_tests(self):
135135
if not rm.check_secure_delete_capability():
136136
raise AssertionError("Secure file deletion is not possible.")
137137

138-
def get_wordlist(self, locale: Text) -> List[str]:
138+
def get_wordlist(self, locale: 'Text') -> 'List[str]':
139139
"""" Ensure the wordlist for the desired locale is read and available
140140
in the words global variable. If there is no wordlist for the
141141
desired local, fallback to the default english wordlist.

securedrop/journalist_app/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
_insecure_views = ['main.login', 'main.select_logo', 'static']
3939

4040

41-
def create_app(config: SDConfig) -> Flask:
41+
def create_app(config: 'SDConfig') -> Flask:
4242
app = Flask(__name__,
4343
template_folder=config.JOURNALIST_TEMPLATES_DIR,
4444
static_folder=path.join(config.SECUREDROP_ROOT, 'static'))
@@ -81,14 +81,14 @@ def create_app(config: SDConfig) -> Flask:
8181
)
8282

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

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

128128
@app.before_request
129-
def setup_g() -> Optional[Response]:
129+
def setup_g() -> 'Optional[Response]':
130130
"""Store commonly used values in Flask's special g object"""
131131
if 'expires' in session and datetime.utcnow() >= session['expires']:
132132
session.clear()

securedrop/journalist_app/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def col_delete(cols_selected):
254254
return redirect(url_for('main.index'))
255255

256256

257-
def make_password(config: SDConfig) -> str:
257+
def make_password(config: 'SDConfig') -> str:
258258
while True:
259259
password = current_app.crypto_util.genrandomid(
260260
7,

securedrop/models.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
ARGON2_PARAMS = dict(memory_cost=2**16, rounds=4, parallelism=2)
4343

4444

45-
def get_one_or_else(query: Query,
46-
logger: Logger,
47-
failure_method: Callable[[int], None]) -> None:
45+
def get_one_or_else(query: 'Query',
46+
logger: 'Logger',
47+
failure_method: 'Callable[[int], None]') -> None:
4848
try:
4949
return query.one()
5050
except MultipleResultsFound as e:
@@ -97,7 +97,7 @@ def journalist_filename(self) -> str:
9797
return ''.join([c for c in self.journalist_designation.lower().replace(
9898
' ', '_') if c in valid_chars])
9999

100-
def documents_messages_count(self) -> Dict[str, int]:
100+
def documents_messages_count(self) -> 'Dict[str, int]':
101101
self.docs_msgs_count = {'messages': 0, 'documents': 0}
102102
for submission in self.submissions:
103103
if submission.filename.endswith('msg.gpg'):
@@ -108,7 +108,7 @@ def documents_messages_count(self) -> Dict[str, int]:
108108
return self.docs_msgs_count
109109

110110
@property
111-
def collection(self) -> List[Union[Submission, Reply]]:
111+
def collection(self) -> 'List[Union[Submission, Reply]]':
112112
"""Return the list of submissions and replies for this source, sorted
113113
in ascending order by the filename/interaction count."""
114114
collection = [] # type: List[Union[Submission, Reply]]
@@ -141,7 +141,7 @@ def public_key(self, value: str) -> None:
141141
def public_key(self) -> None:
142142
raise NotImplementedError
143143

144-
def to_json(self) -> Dict[str, Union[str, bool, int, str]]:
144+
def to_json(self) -> 'Dict[str, Union[str, bool, int, str]]':
145145
docs_msg_count = self.documents_messages_count()
146146

147147
if self.last_updated:
@@ -212,7 +212,7 @@ def __init__(self, source: Source, filename: str) -> None:
212212
def __repr__(self) -> str:
213213
return '<Submission %r>' % (self.filename)
214214

215-
def to_json(self) -> Dict[str, Union[str, int, bool]]:
215+
def to_json(self) -> 'Dict[str, Union[str, int, bool]]':
216216
json_submission = {
217217
'source_url': url_for('api.single_source',
218218
source_uuid=self.source.uuid),
@@ -260,7 +260,7 @@ class Reply(db.Model):
260260
deleted_by_source = Column(Boolean, default=False, nullable=False)
261261

262262
def __init__(self,
263-
journalist: Journalist,
263+
journalist: 'Journalist',
264264
source: Source,
265265
filename: str) -> None:
266266
self.journalist_id = journalist.id
@@ -273,7 +273,7 @@ def __init__(self,
273273
def __repr__(self) -> str:
274274
return '<Reply %r>' % (self.filename)
275275

276-
def to_json(self) -> Dict[str, Union[str, int, bool]]:
276+
def to_json(self) -> 'Dict[str, Union[str, int, bool]]':
277277
username = "deleted"
278278
first_name = ""
279279
last_name = ""
@@ -307,7 +307,7 @@ class SourceStar(db.Model):
307307
source_id = Column("source_id", Integer, ForeignKey('sources.id'))
308308
starred = Column("starred", Boolean, default=True)
309309

310-
def __eq__(self, other: Any) -> bool:
310+
def __eq__(self, other: 'Any') -> bool:
311311
if isinstance(other, SourceStar):
312312
return (self.source_id == other.source_id and
313313
self.id == other.id and self.starred == other.starred)
@@ -418,10 +418,10 @@ class Journalist(db.Model):
418418
def __init__(self,
419419
username: str,
420420
password: str,
421-
first_name: Optional[str] = None,
422-
last_name: Optional[str] = None,
421+
first_name: 'Optional[str]' = None,
422+
last_name: 'Optional[str]' = None,
423423
is_admin: bool = False,
424-
otp_secret: Optional[str] = None) -> None:
424+
otp_secret: 'Optional[str]' = None) -> None:
425425

426426
self.check_username_acceptable(username)
427427
self.username = username
@@ -547,14 +547,14 @@ def set_hotp_secret(self, otp_secret: str) -> None:
547547
self.hotp_counter = 0
548548

549549
@property
550-
def totp(self) -> OTP:
550+
def totp(self) -> 'OTP':
551551
if self.is_totp:
552552
return pyotp.TOTP(self.otp_secret)
553553
else:
554554
raise ValueError('{} is not using TOTP'.format(self))
555555

556556
@property
557-
def hotp(self) -> OTP:
557+
def hotp(self) -> 'OTP':
558558
if not self.is_totp:
559559
return pyotp.HOTP(self.otp_secret)
560560
else:
@@ -677,7 +677,7 @@ def validate_token_is_not_expired_or_invalid(token):
677677
return True
678678

679679
@staticmethod
680-
def validate_api_token_and_get_user(token: str) -> Union[Journalist, None]:
680+
def validate_api_token_and_get_user(token: str) -> 'Union[Journalist, None]':
681681
s = TimedJSONWebSignatureSerializer(current_app.config['SECRET_KEY'])
682682
try:
683683
data = s.loads(token)
@@ -690,7 +690,7 @@ def validate_api_token_and_get_user(token: str) -> Union[Journalist, None]:
690690

691691
return Journalist.query.get(data['id'])
692692

693-
def to_json(self) -> Dict[str, Union[str, bool, str]]:
693+
def to_json(self) -> 'Dict[str, Union[str, bool, str]]':
694694
json_user = {
695695
'username': self.username,
696696
'last_login': self.last_access.isoformat() + 'Z',

securedrop/source_app/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from sdconfig import SDConfig # noqa: F401
3232

3333

34-
def create_app(config: SDConfig) -> Flask:
34+
def create_app(config: 'SDConfig') -> Flask:
3535
app = Flask(__name__,
3636
template_folder=config.SOURCE_TEMPLATES_DIR,
3737
static_folder=path.join(config.SECUREDROP_ROOT, 'static'))

securedrop/store.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ def path_without_filesystem_id(self, filename: str) -> str:
190190
return absolute
191191

192192
def get_bulk_archive(self,
193-
selected_submissions: List,
194-
zip_directory: str = '') -> _TemporaryFileWrapper:
193+
selected_submissions: 'List',
194+
zip_directory: str = '') -> '_TemporaryFileWrapper':
195195
"""Generate a zip file from the selected submissions"""
196196
zip_file = tempfile.NamedTemporaryFile(
197197
prefix='tmp_securedrop_bulk_dl_',
@@ -299,7 +299,7 @@ def save_file_submission(self,
299299
count: int,
300300
journalist_filename: str,
301301
filename: str,
302-
stream: BufferedIOBase) -> str:
302+
stream: 'BufferedIOBase') -> str:
303303
sanitized_filename = secure_filename(filename)
304304

305305
# We store file submissions in a .gz file for two reasons:
@@ -363,7 +363,7 @@ def save_message_submission(self,
363363
return filename
364364

365365

366-
def async_add_checksum_for_file(db_obj: Union[Submission, Reply]) -> str:
366+
def async_add_checksum_for_file(db_obj: 'Union[Submission, Reply]') -> str:
367367
return create_queue().enqueue(
368368
queued_add_checksum_for_file,
369369
type(db_obj),
@@ -373,7 +373,7 @@ def async_add_checksum_for_file(db_obj: Union[Submission, Reply]) -> str:
373373
)
374374

375375

376-
def queued_add_checksum_for_file(db_model: Union[Type[Submission], Type[Reply]],
376+
def queued_add_checksum_for_file(db_model: 'Union[Type[Submission], Type[Reply]]',
377377
model_id: int,
378378
file_path: str,
379379
db_uri: str) -> str:
@@ -385,8 +385,8 @@ def queued_add_checksum_for_file(db_model: Union[Type[Submission], Type[Reply]],
385385
return "success"
386386

387387

388-
def add_checksum_for_file(session: Session,
389-
db_obj: Union[Submission, Reply],
388+
def add_checksum_for_file(session: 'Session',
389+
db_obj: 'Union[Submission, Reply]',
390390
file_path: str) -> None:
391391
hasher = sha256()
392392
with open(file_path, 'rb') as f:

0 commit comments

Comments
 (0)