Skip to content

Commit

Permalink
Extract _allow_noninteractive method to suppress NonInteractive error.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Aug 10, 2020
1 parent 08a82a7 commit e15122e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions twine/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import contextlib
import logging
import sys
from typing import Any
from typing import ContextManager
from typing import Optional
from typing import cast

Expand Down Expand Up @@ -144,14 +146,14 @@ def username(self) -> Optional[str]:

@property
def password(self) -> Optional[str]:
if self.client_cert:
try:
return cast(Optional[str], self.auth.password)
except exceptions.NonInteractive:
return None

# Workaround for https://github.com/python/mypy/issues/5858
return cast(Optional[str], self.auth.password)
with self._allow_noninteractive():
# Workaround for https://github.com/python/mypy/issues/5858
return cast(Optional[str], self.auth.password)

def _allow_noninteractive(self) -> ContextManager[None]:
"""Bypass NonInteractive error when client cert is present."""
suppressed = (exceptions.NonInteractive,) if self.client_cert else ()
return contextlib.suppress(*suppressed)

@property
def verbose(self) -> bool:
Expand Down

0 comments on commit e15122e

Please sign in to comment.