Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Introduce type linting with mypy #397

Merged
merged 27 commits into from
Dec 7, 2022

Conversation

jdtzmn
Copy link
Contributor

@jdtzmn jdtzmn commented Nov 8, 2022

This PR adds type linting to the SDK using mypy and sets it up as an additional check during CI. A large part of the work here involved fixing existing, previously uncaught errors within the SDK. For a full list of those errors, please refer to the dropdown below.

Full list of resolved errors
algosdk/constants.py:12: error: Need type annotation for "NO_AUTH" (hint: "NO_AUTH: List[<type>] = ...")  [var-annotated]
algosdk/source_map.py:47: error: Argument 2 to "get" of "dict" has incompatible type "None"; expected "int"  [arg-type]
algosdk/source_map.py:50: error: Argument 2 to "get" of "dict" has incompatible type "None"; expected "List[int]"  [arg-type]
algosdk/source_map.py:57: error: Tuple index out of range  [misc]
algosdk/source_map.py:67: error: No overload variant of "__setitem__" of "list" matches argument types "int", "int"  [call-overload]
algosdk/source_map.py:67: note: Possible overload variants:
algosdk/source_map.py:67: note:     def __setitem__(self, SupportsIndex, None, /) -> None
algosdk/source_map.py:67: note:     def __setitem__(self, slice, Iterable[None], /) -> None
algosdk/source_map.py:78: error: Unsupported operand types for & ("None" and "int")  [operator]
algosdk/source_map.py:79: error: Unsupported operand types for & ("None" and "int")  [operator]
algosdk/source_map.py:85: error: Incompatible return value type (got "List[int]", expected "Tuple[int]")  [return-value]
algosdk/dryrun_results.py:66: error: "DryrunTransactionResult" has no attribute "app_call_messages"  [attr-defined]
algosdk/dryrun_results.py:67: error: "DryrunTransactionResult" has no attribute "app_call_messages"  [attr-defined]
algosdk/dryrun_results.py:71: error: "DryrunTransactionResult" has no attribute "logic_sig_messages"  [attr-defined]
algosdk/dryrun_results.py:72: error: "DryrunTransactionResult" has no attribute "logic_sig_messages"  [attr-defined]
algosdk/dryrun_results.py:126: error: Incompatible default for argument "spc" (default has type "None", argument has type "StackPrinterConfig")  [assignment]
algosdk/dryrun_results.py:126: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/dryrun_results.py:126: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/dryrun_results.py:135: error: Incompatible default for argument "spc" (default has type "None", argument has type "StackPrinterConfig")  [assignment]
algosdk/dryrun_results.py:135: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/dryrun_results.py:135: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/dryrun_results.py:146: error: "DryrunTransactionResult" has no attribute "logic_sig_disassembly"  [attr-defined]
algosdk/dryrun_results.py:155: error: "DryrunTraceLine" has no attribute "trace_line"  [attr-defined]
algosdk/dryrun_results.py:185: error: Argument 1 of "__eq__" is incompatible with supertype "object"; supertype defines the argument type as "object"  [override]
algosdk/dryrun_results.py:185: note: This violates the Liskov substitution principle
algosdk/dryrun_results.py:185: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
algosdk/dryrun_results.py:185: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
algosdk/dryrun_results.py:185: note:     def __eq__(self, other: object) -> bool:
algosdk/dryrun_results.py:185: note:         if not isinstance(other, DryrunStackValue):
algosdk/dryrun_results.py:185: note:             return NotImplemented
algosdk/dryrun_results.py:185: note:         return <logic to compare two DryrunStackValue instances>
algosdk/dryrun_results.py:217: error: Invalid index type "Optional[int]" for "List[DryrunStackValue]"; expected type "SupportsIndex"  [index]
algosdk/transaction.py:6: error: Skipping analyzing "msgpack": module is installed, but missing library stubs or py.typed marker  [import]
algosdk/encoding.py:6: error: Skipping analyzing "msgpack": module is installed, but missing library stubs or py.typed marker  [import]
algosdk/future/template.py:321: error: Incompatible default for argument "close_remainder_address" (default has type "None", argument has type "str")  [assignment]
algosdk/future/template.py:321: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/future/template.py:321: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/future/transaction.py:4: error: Skipping analyzing "msgpack": module is installed, but missing library stubs or py.typed marker  [import]
algosdk/future/transaction.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
algosdk/future/transaction.py:2342: error: Incompatible return value type (got "Optional[MultisigTransaction]", expected "MultisigTransaction")  [return-value]
algosdk/future/transaction.py:2736: error: Incompatible default for argument "args" (default has type "None", argument has type "List[bytes]")  [assignment]
algosdk/future/transaction.py:2736: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/future/transaction.py:2736: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/future/transaction.py:2866: error: Incompatible types in assignment (expression has type "bytes", variable has type "None")  [assignment]
algosdk/future/transaction.py:2912: error: Incompatible types in assignment (expression has type "None", variable has type "str")  [assignment]
algosdk/future/transaction.py:3222: error: Module has no attribute "TransactionRejectedError"  [attr-defined]
algosdk/future/transaction.py:3279: error: Item "Transaction" of "Union[Any, Transaction]" has no attribute "accounts"  [union-attr]
algosdk/future/transaction.py:3280: error: Item "Transaction" of "Union[Any, Transaction]" has no attribute "accounts"  [union-attr]
algosdk/future/transaction.py:3281: error: Item "Transaction" of "Union[Any, Transaction]" has no attribute "foreign_apps"  [union-attr]
algosdk/future/transaction.py:3282: error: Item "Transaction" of "Union[Any, Transaction]" has no attribute "foreign_apps"  [union-attr]
algosdk/future/transaction.py:3286: error: Item "Transaction" of "Union[Any, Transaction]" has no attribute "foreign_apps"  [union-attr]
algosdk/future/transaction.py:3289: error: Item "Transaction" of "Union[Any, Transaction]" has no attribute "foreign_assets"  [union-attr]
algosdk/future/transaction.py:3290: error: Item "Transaction" of "Union[Any, Transaction]" has no attribute "foreign_assets"  [union-attr]
algosdk/future/transaction.py:3293: error: Item "Transaction" of "Union[Any, Transaction]" has no attribute "index"  [union-attr]
algosdk/future/transaction.py:3298: error: Item "Transaction" of "Union[Any, Transaction]" has no attribute "local_schema"  [union-attr]
algosdk/future/transaction.py:3304: error: Item "Transaction" of "Union[Any, Transaction]" has no attribute "global_schema"  [union-attr]
algosdk/future/transaction.py:3315: error: Item "Transaction" of "Union[Any, Transaction]" has no attribute "approval_program"  [union-attr]
algosdk/future/transaction.py:3316: error: Item "Transaction" of "Union[Any, Transaction]" has no attribute "clear_program"  [union-attr]
algosdk/future/transaction.py:3323: error: Item "Transaction" of "Union[Any, Transaction]" has no attribute "index"  [union-attr]
algosdk/abi/base_type.py:80: error: Item "None" of "Optional[Match[str]]" has no attribute "group"  [union-attr]
algosdk/abi/base_type.py:81: error: Item "None" of "Optional[Match[str]]" has no attribute "group"  [union-attr]
algosdk/abi/base_type.py:106: error: Item "None" of "Optional[Match[str]]" has no attribute "group"  [union-attr]
algosdk/abi/base_type.py:107: error: Item "None" of "Optional[Match[str]]" has no attribute "group"  [union-attr]
algosdk/abi/base_type.py:129: error: Argument 1 to "append" of "list" has incompatible type "List[ABIType]"; expected "ABIType"  [arg-type]
algosdk/template.py:332: error: Incompatible default for argument "last_valid" (default has type "None", argument has type "int")  [assignment]
algosdk/template.py:332: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/template.py:332: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/template.py:333: error: Incompatible default for argument "close_remainder_address" (default has type "None", argument has type "str")  [assignment]
algosdk/template.py:333: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/template.py:333: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/algod.py:8: error: Skipping analyzing "msgpack": module is installed, but missing library stubs or py.typed marker  [import]
algosdk/abi/uint_type.py:85: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior  [str-bytes-safe]
algosdk/abi/ufixed_type.py:100: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior  [str-bytes-safe]
algosdk/abi/byte_type.py:63: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior  [str-bytes-safe]
algosdk/abi/byte_type.py:67: error: Incompatible return value type (got "int", expected "bytes")  [return-value]
algosdk/abi/bool_type.py:63: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior  [str-bytes-safe]
algosdk/abi/bool_type.py:73: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior  [str-bytes-safe]
algosdk/abi/tuple_type.py:179: error: Argument 1 to "_compress_multiple_bool" of "TupleType" has incompatible type "Union[List[Any], bytes, bytearray]"; expected "List[bool]"  [arg-type]
algosdk/abi/tuple_type.py:232: error: Need type annotation for "dynamic_segments" (hint: "dynamic_segments: List[<type>] = ...")  [var-annotated]
algosdk/abi/tuple_type.py:235: error: Need type annotation for "value_partitions" (hint: "value_partitions: List[<type>] = ...")  [var-annotated]
algosdk/abi/tuple_type.py:294: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior  [str-bytes-safe]
algosdk/abi/tuple_type.py:305: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior  [str-bytes-safe]
algosdk/abi/array_static_type.py:84: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior  [str-bytes-safe]
algosdk/abi/array_dynamic_type.py:61: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior  [str-bytes-safe]
algosdk/abi/address_type.py:56: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior  [str-bytes-safe]
algosdk/abi/address_type.py:63: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior  [str-bytes-safe]
algosdk/abi/address_type.py:65: error: Argument 1 to "bytes" has incompatible type "Union[str, bytes]"; expected "Iterable[SupportsIndex]"  [arg-type]
algosdk/abi/address_type.py:85: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior  [str-bytes-safe]
algosdk/abi/method.py:26: error: Incompatible default for argument "desc" (default has type "None", argument has type "str")  [assignment]
algosdk/abi/method.py:26: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/abi/method.py:26: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/abi/method.py:114: error: Incompatible types in assignment (expression has type "List[Dict[Any, Any]]", target has type "str")  [assignment]
algosdk/abi/method.py:115: error: Incompatible types in assignment (expression has type "Dict[Any, Any]", target has type "str")  [assignment]
algosdk/abi/method.py:159: error: Incompatible default for argument "name" (default has type "None", argument has type "str")  [assignment]
algosdk/abi/method.py:159: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/abi/method.py:159: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/abi/method.py:159: error: Incompatible default for argument "desc" (default has type "None", argument has type "str")  [assignment]
algosdk/abi/method.py:167: error: Incompatible types in assignment (expression has type "ABIType", variable has type "str")  [assignment]
algosdk/abi/method.py:211: error: Incompatible default for argument "desc" (default has type "None", argument has type "str")  [assignment]
algosdk/abi/method.py:211: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/abi/method.py:211: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/abi/method.py:216: error: Incompatible types in assignment (expression has type "ABIType", variable has type "str")  [assignment]
algosdk/abi/interface.py:18: error: Incompatible default for argument "desc" (default has type "None", argument has type "str")  [assignment]
algosdk/abi/interface.py:18: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/abi/interface.py:18: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/abi/interface.py:41: error: Incompatible types in assignment (expression has type "List[Dict[Any, Any]]", target has type "str")  [assignment]
algosdk/abi/contract.py:23: error: Incompatible default for argument "desc" (default has type "None", argument has type "str")  [assignment]
algosdk/abi/contract.py:23: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/abi/contract.py:23: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/abi/contract.py:24: error: Incompatible default for argument "networks" (default has type "None", argument has type "Dict[str, NetworkInfo]")  [assignment]
algosdk/abi/contract.py:24: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/abi/contract.py:24: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/abi/contract.py:49: error: Incompatible types in assignment (expression has type "List[Dict[Any, Any]]", target has type "str")  [assignment]
algosdk/abi/contract.py:50: error: Incompatible types in assignment (expression has type "Dict[str, Dict[Any, Any]]", target has type "str")  [assignment]
algosdk/atomic_transaction_composer.py:40: error: Incompatible default for argument "zero_value" (default has type "None", argument has type "T")  [assignment]
algosdk/atomic_transaction_composer.py:40: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/atomic_transaction_composer.py:40: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/atomic_transaction_composer.py:91: error: Need type annotation for "method_dict" (hint: "method_dict: Dict[<type>, <type>] = ...")  [var-annotated]
algosdk/atomic_transaction_composer.py:92: error: Need type annotation for "txn_list" (hint: "txn_list: List[<type>] = ...")  [var-annotated]
algosdk/atomic_transaction_composer.py:93: error: Need type annotation for "signed_txns" (hint: "signed_txns: List[<type>] = ...")  [var-annotated]
algosdk/atomic_transaction_composer.py:94: error: Need type annotation for "tx_ids" (hint: "tx_ids: List[<type>] = ...")  [var-annotated]
algosdk/atomic_transaction_composer.py:163: error: Incompatible default for argument "method_args" (default has type "None", argument has type "List[Union[Any, TransactionWithSigner]]")  [assignment]
algosdk/atomic_transaction_composer.py:163: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/atomic_transaction_composer.py:163: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/atomic_transaction_composer.py:165: error: Incompatible default for argument "local_schema" (default has type "None", argument has type "StateSchema")  [assignment]
algosdk/atomic_transaction_composer.py:165: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/atomic_transaction_composer.py:165: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/atomic_transaction_composer.py:166: error: Incompatible default for argument "global_schema" (default has type "None", argument has type "StateSchema")  [assignment]
algosdk/atomic_transaction_composer.py:166: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/atomic_transaction_composer.py:166: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/atomic_transaction_composer.py:167: error: Incompatible default for argument "approval_program" (default has type "None", argument has type "bytes")  [assignment]
algosdk/atomic_transaction_composer.py:167: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/atomic_transaction_composer.py:167: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/atomic_transaction_composer.py:168: error: Incompatible default for argument "clear_program" (default has type "None", argument has type "bytes")  [assignment]
algosdk/atomic_transaction_composer.py:168: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/atomic_transaction_composer.py:168: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/atomic_transaction_composer.py:169: error: Incompatible default for argument "extra_pages" (default has type "None", argument has type "int")  [assignment]
algosdk/atomic_transaction_composer.py:169: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/atomic_transaction_composer.py:169: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/atomic_transaction_composer.py:170: error: Incompatible default for argument "accounts" (default has type "None", argument has type "List[str]")  [assignment]
algosdk/atomic_transaction_composer.py:170: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/atomic_transaction_composer.py:170: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/atomic_transaction_composer.py:170: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)
algosdk/atomic_transaction_composer.py:171: error: Incompatible default for argument "foreign_apps" (default has type "None", argument has type "List[int]")  [assignment]
algosdk/atomic_transaction_composer.py:171: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/atomic_transaction_composer.py:171: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/atomic_transaction_composer.py:172: error: Incompatible default for argument "foreign_assets" (default has type "None", argument has type "List[int]")  [assignment]
algosdk/atomic_transaction_composer.py:172: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/atomic_transaction_composer.py:172: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/atomic_transaction_composer.py:173: error: Incompatible default for argument "note" (default has type "None", argument has type "bytes")  [assignment]
algosdk/atomic_transaction_composer.py:173: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/atomic_transaction_composer.py:173: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/atomic_transaction_composer.py:174: error: Incompatible default for argument "lease" (default has type "None", argument has type "bytes")  [assignment]
algosdk/atomic_transaction_composer.py:174: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/atomic_transaction_composer.py:174: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/atomic_transaction_composer.py:175: error: Incompatible default for argument "rekey_to" (default has type "None", argument has type "str")  [assignment]
algosdk/atomic_transaction_composer.py:175: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/atomic_transaction_composer.py:175: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/atomic_transaction_composer.py:176: error: Incompatible default for argument "boxes" (default has type "None", argument has type "List[Tuple[int, bytes]]")  [assignment]
algosdk/atomic_transaction_composer.py:176: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
algosdk/atomic_transaction_composer.py:176: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
algosdk/atomic_transaction_composer.py:408: error: Need type annotation for "signer_indexes" (hint: "signer_indexes: Dict[<type>, <type>] = ...")  [var-annotated]
algosdk/atomic_transaction_composer.py:514: error: Argument "raw_value" to "ABIResult" has incompatible type "None"; expected "bytes"  [arg-type]
algosdk/atomic_transaction_composer.py:549: error: Argument "raw_value" to "ABIResult" has incompatible type "Optional[bytes]"; expected "bytes"  [arg-type]
algosdk/atomic_transaction_composer.py:552: error: Argument "tx_info" to "ABIResult" has incompatible type "Optional[Any]"; expected "Dict[Any, Any]"  [arg-type]
Found 101 errors in 22 files (checked 57 source files)

Testing

  • Confirm that the py.typed marker works correctly.

)


class DryrunTrace:
def __init__(self, trace: List[dict]):
self.trace = [DryrunTraceLine(line) for line in trace]

def get_trace(self) -> List[str]:
Copy link
Contributor Author

@jdtzmn jdtzmn Nov 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this method as it is never used and will error if it ever is since the line.trace_line() method does not exist.

algosdk/abi/base_type.py Outdated Show resolved Hide resolved
)
current_arg = populate_foreign_array(
current_arg: Any = populate_foreign_array(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this should be a stricter type but it cannot be made any stricter until the parameter type for method_args is constrained to not include Any. To make that argument more specific would likely require specifying types in other places throughout the abi package and is therefore outside the scope of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good start - agreed we can tackle them outside this PR.

@jdtzmn jdtzmn marked this pull request as ready for review November 17, 2022 21:12
@@ -2,7 +2,17 @@
import copy
from abc import ABC, abstractmethod
from enum import IntEnum
from typing import Any, List, Optional, Tuple, TypeVar, Union
from typing import (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd appreciate a closer review of this file because I am not yet very familiar with the ABI types and I found it difficult to determine the types of certain variables from their context.

Copy link
Contributor

@algochoi algochoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate the effort on adding stricter typing here - this will reduce a lot of maintenance burden 👏

I'm still looking over the PR but here are my immediate comments to your questions. I also opened up a child PR here for reference: jdtzmn#1

algosdk/abi/byte_type.py Show resolved Hide resolved
Copy link
Contributor

@algochoi algochoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typing suggestions look good! Part 1 of my review is shown in this child PR - feel free to cherry pick or close and make a new commit as you see fit.

I would also suggest adding a mypy config file (mypy.ini) to the root. If not specified, mypy seems to use a config from the user's local directory, which might be inconsistent with the one that the CI uses. I don't have a preference to which particular set of configs we use, so we can start off with a small set or something that you think is appropriate.

requirements.txt Show resolved Hide resolved
)
current_arg = populate_foreign_array(
current_arg: Any = populate_foreign_array(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good start - agreed we can tackle them outside this PR.

@jdtzmn
Copy link
Contributor Author

jdtzmn commented Dec 5, 2022

I have confirmed locally that the types are included when installing from the tar.gz built using python setup.py sdist. I also confirmed that types are not included when not marked within MANIFEST.in and setup.py.

Copy link
Contributor

@michaeldiamant michaeldiamant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdtzmn Thanks for your efforts here to defend against various classes of error with mypy! ☕

Via inspection of python setup.py sdist | less, I confirmed source distribution contains the mypy stubs as intended.

@michaeldiamant
Copy link
Contributor

Merging - We can extend mypy to examples + tests in a subsequent PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants