Skip to content

Commit

Permalink
pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M committed Sep 27, 2023
1 parent 07c8b3c commit 27db43c
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 99 deletions.
20 changes: 10 additions & 10 deletions bindings/python/iota_sdk/types/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ class AddressWithUnspentOutputs():
output_ids: bool


def address_from_dict(dict: Dict[str, Any]) -> Union[Ed25519Address, AccountAddress, NFTAddress]:
def address_from_dict(d: Dict[str, Any]) -> Union[Ed25519Address, AccountAddress, NFTAddress]:
"""
Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary.
Arguments:
* `dict`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
* `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
"""
type = dict['type']
if type == AddressType.ED25519:
return Ed25519Address.from_dict(dict)
if type == AddressType.ACCOUNT:
return AccountAddress.from_dict(dict)
if type == AddressType.NFT:
return NFTAddress.from_dict(dict)
raise Exception(f'invalid address type: {type}')
address_type = d['type']
if address_type == AddressType.ED25519:
return Ed25519Address.from_dict(d)
if address_type == AddressType.ACCOUNT:
return AccountAddress.from_dict(d)
if address_type == AddressType.NFT:
return NFTAddress.from_dict(d)
raise Exception(f'invalid address type: {address_type}')


def addresses_from_dicts(
Expand Down
22 changes: 11 additions & 11 deletions bindings/python/iota_sdk/types/context_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ class RewardContextInput(ContextInput):
init=False)


def context_input_from_dict(dict: Dict[str, Any]) -> Union[CommitmentContextInput,
BlockIssuanceCreditContextInput, RewardContextInput]:
def context_input_from_dict(d: Dict[str, Any]) -> Union[CommitmentContextInput,
BlockIssuanceCreditContextInput, RewardContextInput]:
"""
Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary.
Arguments:
* `dict`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
* `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
"""
type = dict['type']
if type == ContextInputType.Commitment:
return CommitmentContextInput.from_dict(dict)
if type == ContextInputType.BlockIssuanceCredit:
return BlockIssuanceCreditContextInput.from_dict(dict)
if type == ContextInputType.Reward:
return RewardContextInput.from_dict(dict)
raise Exception(f'invalid context input type: {type}')
context_input_type = dict['type']
if context_input_type == ContextInputType.Commitment:
return CommitmentContextInput.from_dict(d)
if context_input_type == ContextInputType.BlockIssuanceCredit:
return BlockIssuanceCreditContextInput.from_dict(d)
if context_input_type == ContextInputType.Reward:
return RewardContextInput.from_dict(d)
raise Exception(f'invalid context input type: {context_input_type}')


def context_inputs_from_dicts(
Expand Down
34 changes: 17 additions & 17 deletions bindings/python/iota_sdk/types/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,28 @@ class StakingFeature(Feature):
init=False)


def feature_from_dict(dict: Dict[str, Any]) -> Union[SenderFeature, IssuerFeature,
MetadataFeature, TagFeature, BlockIssuerFeature, StakingFeature]:
def feature_from_dict(d: Dict[str, Any]) -> Union[SenderFeature, IssuerFeature,
MetadataFeature, TagFeature, BlockIssuerFeature, StakingFeature]:
"""
Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary.
Arguments:
* `dict`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
* `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
"""
type = dict['type']
if type == FeatureType.Sender:
return SenderFeature.from_dict(dict)
if type == FeatureType.Issuer:
return IssuerFeature.from_dict(dict)
if type == FeatureType.Metadata:
return MetadataFeature.from_dict(dict)
if type == FeatureType.Tag:
return TagFeature.from_dict(dict)
if type == FeatureType.BlockIssuer:
return BlockIssuerFeature.from_dict(dict)
if type == FeatureType.Staking:
return StakingFeature.from_dict(dict)
raise Exception(f'invalid feature type: {type}')
feature_type = d['type']
if feature_type == FeatureType.Sender:
return SenderFeature.from_dict(d)
if feature_type == FeatureType.Issuer:
return IssuerFeature.from_dict(d)
if feature_type == FeatureType.Metadata:
return MetadataFeature.from_dict(d)
if feature_type == FeatureType.Tag:
return TagFeature.from_dict(d)
if feature_type == FeatureType.BlockIssuer:
return BlockIssuerFeature.from_dict(d)
if feature_type == FeatureType.Staking:
return StakingFeature.from_dict(d)
raise Exception(f'invalid feature type: {feature_type}')


def features_from_dicts(dicts: List[Dict[str, Any]]) -> List[Union[SenderFeature,
Expand Down
34 changes: 17 additions & 17 deletions bindings/python/iota_sdk/types/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations
from dataclasses import dataclass, field
from dataclasses_json import config
from enum import IntEnum
from typing import Dict, Optional, List, Union, Any
from dataclasses import dataclass, field
from dataclasses_json import config
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.feature import features_from_dicts, SenderFeature, IssuerFeature, MetadataFeature, TagFeature
from iota_sdk.types.native_token import NativeToken
Expand Down Expand Up @@ -227,26 +227,26 @@ class DelegationOutput(Output):
OutputType.Delegation), init=False)


def output_from_dict(dict: Dict[str, Any]) -> Union[BasicOutput, AccountOutput,
FoundryOutput, NftOutput, DelegationOutput]:
def output_from_dict(d: Dict[str, Any]) -> Union[BasicOutput, AccountOutput,
FoundryOutput, NftOutput, DelegationOutput]:
"""
Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary.
Arguments:
* `dict`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
* `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
"""
type = dict['type']
if type == OutputType.Basic:
return BasicOutput.from_dict(dict)
if type == OutputType.Account:
return AccountOutput.from_dict(dict)
if type == OutputType.Foundry:
return FoundryOutput.from_dict(dict)
if type == OutputType.Nft:
return NftOutput.from_dict(dict)
if type == OutputType.Delegation:
return DelegationOutput.from_dict(dict)
raise Exception(f'invalid output type: {type}')
output_type = dict['type']
if output_type == OutputType.Basic:
return BasicOutput.from_dict(d)
if output_type == OutputType.Account:
return AccountOutput.from_dict(d)
if output_type == OutputType.Foundry:
return FoundryOutput.from_dict(d)
if output_type == OutputType.Nft:
return NftOutput.from_dict(d)
if output_type == OutputType.Delegation:
return DelegationOutput.from_dict(d)
raise Exception(f'invalid output type: {output_type}')


def outputs_from_dicts(dicts: List[Dict[str, Any]]) -> List[Union[BasicOutput,
Expand Down
10 changes: 5 additions & 5 deletions bindings/python/iota_sdk/types/output_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations
from typing import Dict, Optional, Union
from dataclasses import dataclass, field
from dataclasses_json import config
from typing import Dict, Optional, Union
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.output import AccountOutput, BasicOutput, DelegationOutput, FoundryOutput, NftOutput, outputs_from_dicts

Expand Down Expand Up @@ -67,9 +67,9 @@ def from_dict(cls, data_dict: Dict) -> OutputWithMetadata:
def as_dict(self):
"""Returns a dictionary representation of OutputWithMetadata, with the fields metadata and output.
"""
config = {}
d = {}

config['metadata'] = self.metadata.__dict__
config['output'] = self.output.as_dict()
d['metadata'] = self.metadata.__dict__
d['output'] = self.output.as_dict()

return config
return d
16 changes: 8 additions & 8 deletions bindings/python/iota_sdk/types/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ class TransactionPayload(Payload):
init=False)


def payload_from_dict(dict: Dict[str, Any]) -> Union[TaggedDataPayload, TransactionPayload]:
def payload_from_dict(d: Dict[str, Any]) -> Union[TaggedDataPayload, TransactionPayload]:
"""
Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary.
Arguments:
* `dict`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
* `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
"""
type = dict['type']
if type == PayloadType.TaggedData:
return TaggedDataPayload.from_dict(dict)
if type == PayloadType.Transaction:
return TransactionPayload.from_dict(dict)
raise Exception(f'invalid payload type: {type}')
payload_type = d['type']
if payload_type == PayloadType.TaggedData:
return TaggedDataPayload.from_dict(d)
if payload_type == PayloadType.Transaction:
return TransactionPayload.from_dict(d)
raise Exception(f'invalid payload type: {payload_type}')


def payloads_from_dicts(
Expand Down
24 changes: 12 additions & 12 deletions bindings/python/iota_sdk/types/unlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,23 @@ class NftUnlock:
type: int = field(default_factory=lambda: int(UnlockType.Nft), init=False)


def unlock_from_dict(dict: Dict[str, Any]) -> Union[SignatureUnlock, ReferenceUnlock, AccountUnlock, NftUnlock]:
def unlock_from_dict(d: Dict[str, Any]) -> Union[SignatureUnlock, ReferenceUnlock, AccountUnlock, NftUnlock]:
"""
Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary.
Arguments:
* `dict`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
* `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
"""
type = dict['type']
if type == UnlockType.Signature:
return SignatureUnlock.from_dict(dict)
if type == UnlockType.Reference:
return ReferenceUnlock.from_dict(dict)
if type == UnlockType.Account:
return AccountUnlock.from_dict(dict)
if type == UnlockType.Nft:
return NftUnlock.from_dict(dict)
raise Exception(f'invalid unlock type: {type}')
unlock_type = d['type']
if unlock_type == UnlockType.Signature:
return SignatureUnlock.from_dict(d)
if unlock_type == UnlockType.Reference:
return ReferenceUnlock.from_dict(d)
if unlock_type == UnlockType.Account:
return AccountUnlock.from_dict(d)
if unlock_type == UnlockType.Nft:
return NftUnlock.from_dict(d)
raise Exception(f'invalid unlock type: {unlock_type}')


def unlocks_from_dicts(dicts: List[Dict[str, Any]]) -> List[Union[SignatureUnlock,
Expand Down
39 changes: 20 additions & 19 deletions bindings/python/iota_sdk/types/unlock_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,30 +149,31 @@ class ImmutableAccountAddressUnlockCondition(UnlockCondition):
UnlockConditionType.ImmutableAccountAddress), init=False)


def unlock_condition_from_dict(dict: Dict[str, Any]) -> Union[AddressUnlockCondition, StorageDepositReturnUnlockCondition, TimelockUnlockCondition,
ExpirationUnlockCondition, StateControllerAddressUnlockCondition, GovernorAddressUnlockCondition, ImmutableAccountAddressUnlockCondition]:
def unlock_condition_from_dict(d: Dict[str, Any]) -> Union[AddressUnlockCondition, StorageDepositReturnUnlockCondition, TimelockUnlockCondition,
ExpirationUnlockCondition, StateControllerAddressUnlockCondition, GovernorAddressUnlockCondition, ImmutableAccountAddressUnlockCondition]:
"""
Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary.
Arguments:
* `dict`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
* `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
"""
type = dict['type']
if type == UnlockConditionType.Address:
return AddressUnlockCondition.from_dict(dict)
if type == UnlockConditionType.StorageDepositReturn:
return StorageDepositReturnUnlockCondition.from_dict(dict)
if type == UnlockConditionType.Timelock:
return TimelockUnlockCondition.from_dict(dict)
if type == UnlockConditionType.Expiration:
return ExpirationUnlockCondition.from_dict(dict)
if type == UnlockConditionType.StateControllerAddress:
return StateControllerAddressUnlockCondition.from_dict(dict)
if type == UnlockConditionType.GovernorAddress:
return GovernorAddressUnlockCondition.from_dict(dict)
if type == UnlockConditionType.ImmutableAccountAddress:
return ImmutableAccountAddressUnlockCondition.from_dict(dict)
raise Exception(f'invalid unlock condition type: {type}')
# pylint: disable=R0911
uc_type = d['type']
if uc_type == UnlockConditionType.Address:
return AddressUnlockCondition.from_dict(d)
if uc_type == UnlockConditionType.StorageDepositReturn:
return StorageDepositReturnUnlockCondition.from_dict(d)
if uc_type == UnlockConditionType.Timelock:
return TimelockUnlockCondition.from_dict(d)
if uc_type == UnlockConditionType.Expiration:
return ExpirationUnlockCondition.from_dict(d)
if uc_type == UnlockConditionType.StateControllerAddress:
return StateControllerAddressUnlockCondition.from_dict(d)
if uc_type == UnlockConditionType.GovernorAddress:
return GovernorAddressUnlockCondition.from_dict(d)
if uc_type == UnlockConditionType.ImmutableAccountAddress:
return ImmutableAccountAddressUnlockCondition.from_dict(d)
raise Exception(f'invalid unlock condition type: {uc_type}')


def unlock_conditions_from_dicts(dicts: List[Dict[str, Any]]) -> List[Union[AddressUnlockCondition, StorageDepositReturnUnlockCondition, TimelockUnlockCondition,
Expand Down

0 comments on commit 27db43c

Please sign in to comment.