Skip to content

Commit

Permalink
a bit more pythonic syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
eschutho committed Sep 26, 2022
1 parent 978232b commit 7ac5ca0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 22 deletions.
8 changes: 3 additions & 5 deletions superset/db_engine_specs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,9 +1614,7 @@ def get_impersonation_key(cls, user: Optional[User]) -> Any:
return user.username if user else None

@classmethod
def mask_encrypted_extra(
cls, encrypted_extra: Union[str, None]
) -> Union[str, None]:
def mask_encrypted_extra(cls, encrypted_extra: Optional[str]) -> Optional[str]:
"""
Mask ``encrypted_extra``.
Expand All @@ -1630,8 +1628,8 @@ def mask_encrypted_extra(
# pylint: disable=unused-argument
@classmethod
def unmask_encrypted_extra(
cls, old: Union[str, None], new: Union[str, None]
) -> Union[str, None]:
cls, old: Optional[str], new: Optional[str]
) -> Optional[str]:
"""
Remove masks from ``encrypted_extra``.
Expand Down
10 changes: 4 additions & 6 deletions superset/db_engine_specs/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import re
import urllib
from datetime import datetime
from typing import Any, Dict, List, Optional, Pattern, Tuple, Type, TYPE_CHECKING, Union
from typing import Any, Dict, List, Optional, Pattern, Tuple, Type, TYPE_CHECKING

import pandas as pd
from apispec import APISpec
Expand Down Expand Up @@ -396,9 +396,7 @@ def get_parameters_from_uri(
raise ValidationError("Invalid service credentials")

@classmethod
def mask_encrypted_extra(
cls, encrypted_extra: Union[str, None]
) -> Union[str, None]:
def mask_encrypted_extra(cls, encrypted_extra: Optional[str]) -> Optional[str]:
try:
config = json.loads(encrypted_extra) # type:ignore
except (json.JSONDecodeError, TypeError):
Expand All @@ -413,8 +411,8 @@ def mask_encrypted_extra(

@classmethod
def unmask_encrypted_extra(
cls, old: Union[str, None], new: Union[str, None]
) -> Union[str, None]:
cls, old: Optional[str], new: Optional[str]
) -> Optional[str]:
"""
Reuse ``private_key`` if available and unchanged.
"""
Expand Down
10 changes: 4 additions & 6 deletions superset/db_engine_specs/gsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import json
import re
from contextlib import closing
from typing import Any, Dict, List, Optional, Pattern, Tuple, TYPE_CHECKING, Union
from typing import Any, Dict, List, Optional, Pattern, Tuple, TYPE_CHECKING

from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
Expand Down Expand Up @@ -138,9 +138,7 @@ def get_parameters_from_uri(
raise ValidationError("Invalid service credentials")

@classmethod
def mask_encrypted_extra(
cls, encrypted_extra: Union[str, None]
) -> Union[str, None]:
def mask_encrypted_extra(cls, encrypted_extra: Optional[str]) -> Optional[str]:
try:
config = json.loads(encrypted_extra) # type:ignore
except (TypeError, json.JSONDecodeError):
Expand All @@ -155,8 +153,8 @@ def mask_encrypted_extra(

@classmethod
def unmask_encrypted_extra(
cls, old: Union[str, None], new: Union[str, None]
) -> Union[str, None]:
cls, old: Optional[str], new: Optional[str]
) -> Optional[str]:
"""
Reuse ``private_key`` if available and unchanged.
"""
Expand Down
4 changes: 2 additions & 2 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from contextlib import closing
from copy import deepcopy
from datetime import datetime
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type

import numpy
import pandas as pd
Expand Down Expand Up @@ -248,7 +248,7 @@ def backend(self) -> str:
return sqlalchemy_url.get_backend_name()

@property
def masked_encrypted_extra(self) -> Union[str, None]:
def masked_encrypted_extra(self) -> Optional[str]:
return self.db_engine_spec.mask_encrypted_extra(self.encrypted_extra)

@property
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/db_engine_specs/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def test_unmask_encrypted_extra_when_new_is_empty() -> None:
)
new = None

assert BigQueryEngineSpec.unmask_encrypted_extra(old, new) == None
assert BigQueryEngineSpec.unmask_encrypted_extra(old, new) is None


def test_mask_encrypted_extra_when_empty() -> None:
Expand All @@ -243,4 +243,4 @@ def test_mask_encrypted_extra_when_empty() -> None:
"""
from superset.db_engine_specs.bigquery import BigQueryEngineSpec

assert BigQueryEngineSpec.mask_encrypted_extra(None) == None
assert BigQueryEngineSpec.mask_encrypted_extra(None) is None
2 changes: 1 addition & 1 deletion tests/unit_tests/db_engine_specs/test_gsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,4 @@ def test_unmask_encrypted_extra_when_new_is_none() -> None:
)
new = None

assert GSheetsEngineSpec.unmask_encrypted_extra(old, new) == None
assert GSheetsEngineSpec.unmask_encrypted_extra(old, new) is None

0 comments on commit 7ac5ca0

Please sign in to comment.