Skip to content

Commit

Permalink
remove type ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
eschutho committed Sep 29, 2022
1 parent 7ac5ca0 commit ad122fc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
12 changes: 9 additions & 3 deletions superset/db_engine_specs/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,11 @@ def get_parameters_from_uri(

@classmethod
def mask_encrypted_extra(cls, encrypted_extra: Optional[str]) -> Optional[str]:
if encrypted_extra is None:
return encrypted_extra

try:
config = json.loads(encrypted_extra) # type:ignore
config = json.loads(encrypted_extra)
except (json.JSONDecodeError, TypeError):
return encrypted_extra

Expand All @@ -416,9 +419,12 @@ def unmask_encrypted_extra(
"""
Reuse ``private_key`` if available and unchanged.
"""
if old is None or new is None:
return new

try:
old_config = json.loads(old) # type:ignore
new_config = json.loads(new) # type:ignore
old_config = json.loads(old)
new_config = json.loads(new)
except (TypeError, json.JSONDecodeError):
return new

Expand Down
12 changes: 9 additions & 3 deletions superset/db_engine_specs/gsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ def get_parameters_from_uri(

@classmethod
def mask_encrypted_extra(cls, encrypted_extra: Optional[str]) -> Optional[str]:
if encrypted_extra is None:
return encrypted_extra

try:
config = json.loads(encrypted_extra) # type:ignore
config = json.loads(encrypted_extra)
except (TypeError, json.JSONDecodeError):
return encrypted_extra

Expand All @@ -158,9 +161,12 @@ def unmask_encrypted_extra(
"""
Reuse ``private_key`` if available and unchanged.
"""
if old is None or new is None:
return new

try:
old_config = json.loads(old) # type:ignore
new_config = json.loads(new) # type:ignore
old_config = json.loads(old)
new_config = json.loads(new)
except (TypeError, json.JSONDecodeError):
return new

Expand Down
10 changes: 6 additions & 4 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,12 @@ def parameters(self) -> Dict[str, Any]:
masked_encrypted_extra = db_engine_spec.mask_encrypted_extra(
self.encrypted_extra
)
try:
encrypted_config = json.loads(masked_encrypted_extra) # type: ignore
except (TypeError, json.JSONDecodeError):
encrypted_config = {}
encrypted_config = {}
if masked_encrypted_extra is not None:
try:
encrypted_config = json.loads(masked_encrypted_extra)
except (TypeError, json.JSONDecodeError):
pass

try:
# pylint: disable=useless-suppression
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 @@ -186,7 +186,7 @@ def test_unmask_encrypted_extra() -> None:
}
)

assert json.loads(BigQueryEngineSpec.unmask_encrypted_extra(old, new)) == { # type: ignore
assert json.loads(str(BigQueryEngineSpec.unmask_encrypted_extra(old, new))) == {
"credentials_info": {
"project_id": "yellow-unicorn-314419",
"private_key": "SECRET",
Expand All @@ -210,7 +210,7 @@ def test_unmask_encrypted_extra_when_empty() -> None:
}
)

assert json.loads(BigQueryEngineSpec.unmask_encrypted_extra(old, new)) == { # type: ignore
assert json.loads(str(BigQueryEngineSpec.unmask_encrypted_extra(old, new))) == {
"credentials_info": {
"project_id": "yellow-unicorn-314419",
"private_key": "XXXXXXXXXX",
Expand Down
8 changes: 2 additions & 6 deletions tests/unit_tests/db_engine_specs/test_gsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ def test_unmask_encrypted_extra() -> None:
}
)

assert json.loads(
GSheetsEngineSpec.unmask_encrypted_extra(old, new) # type:ignore
) == {
assert json.loads(str(GSheetsEngineSpec.unmask_encrypted_extra(old, new))) == {
"service_account_info": {
"project_id": "yellow-unicorn-314419",
"private_key": "SECRET",
Expand All @@ -254,9 +252,7 @@ def test_unmask_encrypted_extra_when_old_is_none() -> None:
}
)

assert json.loads(
GSheetsEngineSpec.unmask_encrypted_extra(old, new) # type:ignore
) == {
assert json.loads(str(GSheetsEngineSpec.unmask_encrypted_extra(old, new))) == {
"service_account_info": {
"project_id": "yellow-unicorn-314419",
"private_key": "XXXXXXXXXX",
Expand Down

0 comments on commit ad122fc

Please sign in to comment.