Skip to main content
added 288 characters in body
Source Link
InSync
  • 499
  • 3
  • 10

This signature isn't very precise:

class Matrix:
    def __init__(self, arrays: list[list]) -> None:

list[list] means list[list[Any]], but clearly you want a matrix of floats/ints.

Remember, explicit is better than implicit. Always use parametrized generics, even when all type arguments are Any.

class Matrix:
    def __init__(self, arrays: list[list[float]]) -> None:

Also, be sure to specify Matrix as the return type for fromdim():

def fromdim(width: int, height: int) -> Matrix:
    ...

Without this, Mypy would think fromdim() returns Any. Pyright, on the other hand, can infer the correct type. Rely on neither.

This signature isn't very precise:

class Matrix:
    def __init__(self, arrays: list[list]) -> None:

list[list] means list[list[Any]], but clearly you want a matrix of floats/ints.

Remember, explicit is better than implicit. Always use parametrized generics, even when all type arguments are Any.

class Matrix:
    def __init__(self, arrays: list[list[float]]) -> None:

This signature isn't very precise:

class Matrix:
    def __init__(self, arrays: list[list]) -> None:

list[list] means list[list[Any]], but clearly you want a matrix of floats/ints.

Remember, explicit is better than implicit. Always use parametrized generics, even when all type arguments are Any.

class Matrix:
    def __init__(self, arrays: list[list[float]]) -> None:

Also, be sure to specify Matrix as the return type for fromdim():

def fromdim(width: int, height: int) -> Matrix:
    ...

Without this, Mypy would think fromdim() returns Any. Pyright, on the other hand, can infer the correct type. Rely on neither.

Source Link
InSync
  • 499
  • 3
  • 10

This signature isn't very precise:

class Matrix:
    def __init__(self, arrays: list[list]) -> None:

list[list] means list[list[Any]], but clearly you want a matrix of floats/ints.

Remember, explicit is better than implicit. Always use parametrized generics, even when all type arguments are Any.

class Matrix:
    def __init__(self, arrays: list[list[float]]) -> None: