diff --git a/Makefile b/Makefile index 41527d387..809aa969f 100644 --- a/Makefile +++ b/Makefile @@ -40,9 +40,8 @@ black: flake8: flake8 $(ALLPY) -MYPY = pyteal scripts tests mypy: - mypy --show-error-codes $(MYPY) + mypy lint: black flake8 mypy diff --git a/mypy.ini b/mypy.ini index 728b3aef1..6545e4299 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,4 +1,6 @@ [mypy] +files = pyteal,scripts,tests +python_version = 3.10 [mypy-semantic_version.*] ignore_missing_imports = True diff --git a/pyteal/ast/abi/array_base.py b/pyteal/ast/abi/array_base.py index 8920637bc..7fdf51dc6 100644 --- a/pyteal/ast/abi/array_base.py +++ b/pyteal/ast/abi/array_base.py @@ -82,9 +82,9 @@ def decode( self, encoded: Expr, *, - start_index: Expr = None, - end_index: Expr = None, - length: Expr = None + start_index: Expr | None = None, + end_index: Expr | None = None, + length: Expr | None = None ) -> Expr: """Decode a substring of the passed in encoded byte string and set it as this type's value. diff --git a/pyteal/ast/abi/bool.py b/pyteal/ast/abi/bool.py index 6fa6d72a3..26f93bf1b 100644 --- a/pyteal/ast/abi/bool.py +++ b/pyteal/ast/abi/bool.py @@ -94,9 +94,9 @@ def decode( self, encoded: Expr, *, - start_index: Expr = None, - end_index: Expr = None, - length: Expr = None + start_index: Expr | None = None, + end_index: Expr | None = None, + length: Expr | None = None ) -> Expr: if start_index is None: start_index = Int(0) diff --git a/pyteal/ast/abi/reference_type.py b/pyteal/ast/abi/reference_type.py index e1a228245..7e9c5307c 100644 --- a/pyteal/ast/abi/reference_type.py +++ b/pyteal/ast/abi/reference_type.py @@ -64,9 +64,9 @@ def decode( self, encoded: Expr, *, - start_index: Expr = None, - end_index: Expr = None, - length: Expr = None, + start_index: Expr | None = None, + end_index: Expr | None = None, + length: Expr | None = None, ) -> Expr: return uint_decode( self.type_spec().bit_size(), diff --git a/pyteal/ast/abi/transaction.py b/pyteal/ast/abi/transaction.py index 69de7ea29..d10315514 100644 --- a/pyteal/ast/abi/transaction.py +++ b/pyteal/ast/abi/transaction.py @@ -63,7 +63,7 @@ def __str__(self) -> str: class Transaction(BaseType): - def __init__(self, spec: TransactionTypeSpec = None) -> None: + def __init__(self, spec: TransactionTypeSpec | None = None) -> None: if spec is None: super().__init__(TransactionTypeSpec()) else: @@ -97,9 +97,9 @@ def decode( self, encoded: Expr, *, - start_index: Expr = None, - end_index: Expr = None, - length: Expr = None, + start_index: Expr | None = None, + end_index: Expr | None = None, + length: Expr | None = None, ) -> Expr: raise TealInputError("A Transaction cannot be decoded") diff --git a/pyteal/ast/abi/tuple.py b/pyteal/ast/abi/tuple.py index 2d744eeeb..a4748d52c 100644 --- a/pyteal/ast/abi/tuple.py +++ b/pyteal/ast/abi/tuple.py @@ -302,9 +302,9 @@ def decode( self, encoded: Expr, *, - start_index: Expr = None, - end_index: Expr = None, - length: Expr = None, + start_index: Expr | None = None, + end_index: Expr | None = None, + length: Expr | None = None, ) -> Expr: extracted = substring_for_decoding( encoded, start_index=start_index, end_index=end_index, length=length diff --git a/pyteal/ast/abi/type.py b/pyteal/ast/abi/type.py index 6abed2d80..070ddc24a 100644 --- a/pyteal/ast/abi/type.py +++ b/pyteal/ast/abi/type.py @@ -98,9 +98,9 @@ def decode( self, encoded: Expr, *, - start_index: Expr = None, - end_index: Expr = None, - length: Expr = None, + start_index: Expr | None = None, + end_index: Expr | None = None, + length: Expr | None = None, ) -> Expr: """Decode a substring of the passed in encoded string and set it as this type's value. diff --git a/pyteal/ast/abi/uint.py b/pyteal/ast/abi/uint.py index 949eb7c40..0994adb03 100644 --- a/pyteal/ast/abi/uint.py +++ b/pyteal/ast/abi/uint.py @@ -281,9 +281,9 @@ def decode( self, encoded: Expr, *, - start_index: Expr = None, - end_index: Expr = None, - length: Expr = None, + start_index: Expr | None = None, + end_index: Expr | None = None, + length: Expr | None = None, ) -> Expr: return uint_decode( self.type_spec().bit_size(), diff --git a/pyteal/ast/abi/util.py b/pyteal/ast/abi/util.py index 4cece8b49..36b828390 100644 --- a/pyteal/ast/abi/util.py +++ b/pyteal/ast/abi/util.py @@ -22,9 +22,9 @@ def substring_for_decoding( encoded: Expr, *, - start_index: Expr = None, - end_index: Expr = None, - length: Expr = None, + start_index: Expr | None = None, + end_index: Expr | None = None, + length: Expr | None = None, ) -> Expr: """A helper function for getting the substring to decode according to the rules of BaseType.decode.""" if length is not None and end_index is not None: diff --git a/pyteal/ast/acct_test.py b/pyteal/ast/acct_test.py index 8259f8ac6..5991d2ac5 100644 --- a/pyteal/ast/acct_test.py +++ b/pyteal/ast/acct_test.py @@ -63,7 +63,7 @@ def test_acct_param_version_checks(method_name, field_name): account_param_field = AccountParamField[field_name] - def test_unsupported_version(version: int, match: str = None): + def test_unsupported_version(version: int, match: str | None = None): with pytest.raises(pt.TealInputError, match=match): unsupported_options_version = pt.CompileOptions(version=version) expr.__teal__(unsupported_options_version) diff --git a/pyteal/ast/assert_.py b/pyteal/ast/assert_.py index 22dd392dc..9444e9262 100644 --- a/pyteal/ast/assert_.py +++ b/pyteal/ast/assert_.py @@ -14,7 +14,7 @@ class Assert(Expr): """A control flow expression to verify that a condition is true.""" def __init__( - self, cond: Expr, *additional_conds: Expr, comment: str = None + self, cond: Expr, *additional_conds: Expr, comment: str | None = None ) -> None: """Create an assert statement that raises an error if the condition is false. diff --git a/pyteal/ast/bytes.py b/pyteal/ast/bytes.py index 1c7bd09b4..1d842dfc3 100644 --- a/pyteal/ast/bytes.py +++ b/pyteal/ast/bytes.py @@ -21,7 +21,7 @@ def __init__(self, arg1: str | bytes | bytearray) -> None: def __init__(self, arg1: str, arg2: str) -> None: pass - def __init__(self, arg1: str | bytes | bytearray, arg2: str = None) -> None: + def __init__(self, arg1: str | bytes | bytearray, arg2: str | None = None) -> None: """ __init__(arg1: Union[str, bytes, bytearray]) -> None __init__(self, arg1: str, arg2: str) -> None diff --git a/pyteal/ast/comment.py b/pyteal/ast/comment.py index 361694677..75263fe6f 100644 --- a/pyteal/ast/comment.py +++ b/pyteal/ast/comment.py @@ -43,7 +43,7 @@ def has_return(self): CommentExpr.__module__ = "pyteal" -def Comment(comment: str, expr: Expr = None) -> Expr: +def Comment(comment: str, expr: Expr | None = None) -> Expr: """Wrap an existing expression with a comment. This comment will be present in the compiled TEAL source immediately before the first op of the diff --git a/pyteal/ast/if_.py b/pyteal/ast/if_.py index 14cf9d394..18e0df3ad 100644 --- a/pyteal/ast/if_.py +++ b/pyteal/ast/if_.py @@ -17,7 +17,7 @@ class If(Expr): """Simple two-way conditional expression.""" def __init__( - self, cond: Expr, thenBranch: Expr = None, elseBranch: Expr = None + self, cond: Expr, thenBranch: Expr | None = None, elseBranch: Expr | None = None ) -> None: """Create a new If expression. diff --git a/pyteal/ast/maybe.py b/pyteal/ast/maybe.py index 9ae1f0245..e22c79816 100644 --- a/pyteal/ast/maybe.py +++ b/pyteal/ast/maybe.py @@ -20,9 +20,9 @@ def __init__( op: Op, type: TealType, *, - immediate_args: List[Union[int, str]] = None, - args: List[Expr] = None, - compile_check: Callable[["CompileOptions"], None] = None, + immediate_args: List[Union[int, str]] | None = None, + args: List[Expr] | None = None, + compile_check: Callable[["CompileOptions"], None] | None = None, ): """Create a new MaybeValue. diff --git a/pyteal/ast/multi.py b/pyteal/ast/multi.py index e61af4b4a..4fed823a6 100644 --- a/pyteal/ast/multi.py +++ b/pyteal/ast/multi.py @@ -19,8 +19,8 @@ def __init__( op: Op, types: List[TealType], *, - immediate_args: List[Union[int, str]] = None, - args: List[Expr] = None, + immediate_args: List[Union[int, str]] | None = None, + args: List[Expr] | None = None, compile_check: Callable[["CompileOptions"], None] = lambda _: None, ): """Create a new MultiValue. diff --git a/pyteal/ast/opup.py b/pyteal/ast/opup.py index 419fe8e7f..6fe1cc05f 100644 --- a/pyteal/ast/opup.py +++ b/pyteal/ast/opup.py @@ -78,7 +78,7 @@ class OpUp: ) """ - def __init__(self, mode: OpUpMode, target_app_id: Expr = None): + def __init__(self, mode: OpUpMode, target_app_id: Expr | None = None): """Create a new OpUp object. Args: diff --git a/pyteal/ast/return_.py b/pyteal/ast/return_.py index d7537ec26..ba2b695a6 100644 --- a/pyteal/ast/return_.py +++ b/pyteal/ast/return_.py @@ -13,7 +13,7 @@ class Return(Expr): """Return a value from the current execution context.""" - def __init__(self, value: Expr = None) -> None: + def __init__(self, value: Expr | None = None) -> None: """Create a new Return expression. If called from the main program, this will immediately exit the program diff --git a/pyteal/ast/router.py b/pyteal/ast/router.py index 00e7d80a8..9041c8bbf 100644 --- a/pyteal/ast/router.py +++ b/pyteal/ast/router.py @@ -506,8 +506,8 @@ class Router: def __init__( self, name: str, - bare_calls: BareCallActions = None, - descr: str = None, + bare_calls: BareCallActions | None = None, + descr: str | None = None, ) -> None: """ Args: @@ -547,9 +547,9 @@ def __init__( def add_method_handler( self, method_call: ABIReturnSubroutine, - overriding_name: str = None, - method_config: MethodConfig = None, - description: str = None, + overriding_name: str | None = None, + method_config: MethodConfig | None = None, + description: str | None = None, ) -> ABIReturnSubroutine: """Add a method call handler to this Router. @@ -605,17 +605,17 @@ def add_method_handler( def method( self, - func: Callable = None, + func: Callable | None = None, /, *, - name: str = None, - description: str = None, - no_op: CallConfig = None, - opt_in: CallConfig = None, - close_out: CallConfig = None, - clear_state: CallConfig = None, - update_application: CallConfig = None, - delete_application: CallConfig = None, + name: str | None = None, + description: str | None = None, + no_op: CallConfig | None = None, + opt_in: CallConfig | None = None, + close_out: CallConfig | None = None, + clear_state: CallConfig | None = None, + update_application: CallConfig | None = None, + delete_application: CallConfig | None = None, ): """This is an alternative way to register a method, as supposed to :code:`add_method_handler`. diff --git a/pyteal/ast/router_test.py b/pyteal/ast/router_test.py index b1e0f8401..609161860 100644 --- a/pyteal/ast/router_test.py +++ b/pyteal/ast/router_test.py @@ -259,7 +259,7 @@ def multiple_txn( ] -def power_set(no_dup_list: list, length_override: int = None): +def power_set(no_dup_list: list, length_override: int | None = None): """ This function serves as a generator for all possible elements in power_set over `non_dup_list`, which is a list of non-duplicated elements (matches property of a set). diff --git a/pyteal/ast/scratch.py b/pyteal/ast/scratch.py index 463d83d5e..abf8821fe 100644 --- a/pyteal/ast/scratch.py +++ b/pyteal/ast/scratch.py @@ -1,4 +1,4 @@ -from typing import cast, TYPE_CHECKING, Optional +from typing import cast, TYPE_CHECKING from pyteal.types import TealType, require_type from pyteal.config import NUM_SLOTS @@ -17,7 +17,7 @@ class ScratchSlot: # Slot ids under 256 are manually reserved slots nextSlotId = NUM_SLOTS - def __init__(self, requestedSlotId: int = None): + def __init__(self, requestedSlotId: int | None = None): """Initializes a scratch slot with a particular id Args: @@ -38,7 +38,7 @@ def __init__(self, requestedSlotId: int = None): self.id = requestedSlotId self.isReservedSlot = True - def store(self, value: Expr = None) -> Expr: + def store(self, value: Expr | None = None) -> Expr: """Get an expression to store a value in this slot. Args: @@ -102,9 +102,9 @@ class ScratchLoad(Expr): def __init__( self, - slot: ScratchSlot = None, + slot: ScratchSlot | None = None, type: TealType = TealType.anytype, - index_expression: Expr = None, + index_expression: Expr | None = None, ): """Create a new ScratchLoad expression. @@ -168,7 +168,10 @@ class ScratchStore(Expr): """Expression to store a value in scratch space.""" def __init__( - self, slot: Optional[ScratchSlot], value: Expr, index_expression: Expr = None + self, + slot: ScratchSlot | None, + value: Expr, + index_expression: Expr | None = None, ): """Create a new ScratchStore expression. diff --git a/pyteal/ast/scratchvar.py b/pyteal/ast/scratchvar.py index a7d8a2dfa..f0a86e253 100644 --- a/pyteal/ast/scratchvar.py +++ b/pyteal/ast/scratchvar.py @@ -20,7 +20,7 @@ class ScratchVar(AbstractVar): ]) """ - def __init__(self, type: TealType = TealType.anytype, slotId: int = None): + def __init__(self, type: TealType = TealType.anytype, slotId: int | None = None): """Create a new ScratchVar with an optional type. Args: diff --git a/pyteal/ast/subroutine.py b/pyteal/ast/subroutine.py index eeea8950b..26ef53d90 100644 --- a/pyteal/ast/subroutine.py +++ b/pyteal/ast/subroutine.py @@ -133,7 +133,7 @@ def __init__( self.__name: str = name_str if name_str else self.implementation.__name__ def _validate( - self, input_types: list[TealType | None] = None + self, input_types: list[TealType | None] | None = None ) -> tuple[ MappingProxyType[str, Parameter], dict[str, type], @@ -433,7 +433,7 @@ def __init__( subroutine: SubroutineDefinition, args: list[Expr | ScratchVar | abi.BaseType], *, - output_kwarg: OutputKwArgInfo = None, + output_kwarg: OutputKwArgInfo | None = None, ) -> None: super().__init__() self.subroutine = subroutine @@ -674,7 +674,7 @@ def __call__( def name(self) -> str: return self.subroutine.name() - def method_signature(self, overriding_name: str = None) -> str: + def method_signature(self, overriding_name: str | None = None) -> str: if not self.is_abi_routable(): raise TealInputError( "Only registrable methods may return a method signature" diff --git a/pyteal/ir/tealblock.py b/pyteal/ir/tealblock.py index 7ce6259bc..8ceed472e 100644 --- a/pyteal/ir/tealblock.py +++ b/pyteal/ir/tealblock.py @@ -36,7 +36,9 @@ def isTerminal(self) -> bool: return len(self.getOutgoing()) == 0 def validateTree( - self, parent: "TealBlock" = None, visited: List["TealBlock"] = None + self, + parent: "TealBlock | None" = None, + visited: List["TealBlock"] | None = None, ) -> None: """Check that this block and its children have valid parent pointers. @@ -62,7 +64,9 @@ def validateTree( block.validateTree(self, visited) def addIncoming( - self, parent: "TealBlock" = None, visited: List["TealBlock"] = None + self, + parent: "TealBlock | None" = None, + visited: List["TealBlock"] | None = None, ) -> None: """Calculate the parent blocks for this block and its children. @@ -85,8 +89,8 @@ def addIncoming( def validateSlots( self, - slotsInUse: Set["ScratchSlot"] = None, - visited: Set[Tuple[int, ...]] = None, + slotsInUse: Set["ScratchSlot"] | None = None, + visited: Set[Tuple[int, ...]] | None = None, ) -> List[TealCompileError]: if visited is None: visited = set() diff --git a/pyteal/ir/teallabel.py b/pyteal/ir/teallabel.py index 6c6cea98e..5e515886d 100644 --- a/pyteal/ir/teallabel.py +++ b/pyteal/ir/teallabel.py @@ -1,4 +1,4 @@ -from typing import Optional, TYPE_CHECKING +from typing import TYPE_CHECKING from pyteal.ir.tealcomponent import TealComponent from pyteal.ir.labelref import LabelReference @@ -9,7 +9,7 @@ class TealLabel(TealComponent): def __init__( - self, expr: Optional["Expr"], label: LabelReference, comment: str = None + self, expr: "Expr | None", label: LabelReference, comment: str | None = None ) -> None: super().__init__(expr) self.label = label diff --git a/requirements.txt b/requirements.txt index 158039a7b..5ff207492 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ black==22.3.0 flake8==5.0.4 flake8-tidy-imports==4.6.0 graviton@git+https://github.com/algorand/graviton@v0.5.0 -mypy==0.950 +mypy==0.991 pytest==7.2.0 pytest-cov==3.0.0 pytest-timeout==2.1.0