1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Python: current and subsequent classes are not recognized as parameter types...

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    Here is a simple Python code, where classes Point and Vector are defined in same file:

    class Point:
    def __init__(self, x1:int, y1:int):
    self.x = x1; self.y = y1

    @staticmethod
    def from_origin_offset(origin:point, offset:Vector) -> Point:
    return Point(origin.x+offset.x, origin.y+offset.y)
    ....

    class Vector:
    def __init__(self, x1:float, y1:float):
    self.x = x1; self.y = y1


    In method from_origin_offset both types Point and Vector are not recognised in the method declaration.

    This can be fixed by removing explicit types like that:

    @staticmethod
    def from_origin_offset(origin, offset):
    return Point(origin.x+offset.x, origin.y+offset.y)


    however for better readability I prefer to keep explicit types. Is it possible?

    Continue reading...

Compartilhe esta Página