So fügen Sie einer Variablen einen Typ Hinweis hinzu, das sich in einer statischen Methode innerhalb einer Klasse darste

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: So fügen Sie einer Variablen einen Typ Hinweis hinzu, das sich in einer statischen Methode innerhalb einer Klasse darste

by Anonymous » 28 Feb 2025, 05:52

Ich versuche, eine statische Methode in Python mit dem Tippen zu type zu fügen. . Der Typ -Hinweis wird jedoch nicht auf das Selbstargument innerhalb der Funktion selbst angewendet. < /P>

Code: Select all

from typing import Self

class Vect:
x: float
y: float

@staticmethod
def angle(v1: Self, v2: Self):
return math.acos(v1 * v2 / v1.magnitude() / v2.magnitude())
Der Code funktioniert, gibt mir jedoch keine Hinweise in der Winkelmethode für Variablen V1 und v2 .

Top