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 e7ff37d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions twine/settings.py
Expand Up @@ -13,11 +13,13 @@
# 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 Optional
from typing import cast
from typing import ContextManager

from twine import auth
from twine import exceptions
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 e7ff37d

Please sign in to comment.