You can also use typing.cast for the handful of cases where your particular type checker (e.g. MyPy) fails to refine the type properly in a case like the following:
def lookup_usernames(db, user_ids: Optional[List[int]] = None) -> List[str]: if user_ids is None: return [] user_ids = typing.cast(List[int], user_ids) db.executemany('select name from users where id = ?', [(user_id,) for user_id in user_ids]) return db.fetchall() _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/6HJMXQ56FZC5KVVETPWJJFHZJVXIN2UY/ Code of Conduct: http://python.org/psf/codeofconduct/