Hi,
I came across the following function:
I am not familiar with the notation "def getWords(self) -> list[str]:" in the function definition. What does the -> mean?
Also when I invoke the file with python3 I get an error on the line:
TypeError: 'type' object is not subscriptable
Could someone explain or provide some context for the use of -> and the error I see?
I came across the following function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
def getWords( self ) - > list [ str ]: with open ( self .word_list_path, "r" ) as f: word_list = [line.strip() for line in f] return word_list class Ui_MainWindow(QMainWindow): def __init__( self , word_list_path: str ): super ().__init__() self .word_list_path = word_list_path self .speller = SpellCheckWrapper( self .getWords(), self .addToDictionary) self .setupUi() class SpellCheckWrapper: def __init__( self , personal_word_list: list [ str ], addToDictionary: Callable [[ str ], None ] ): # Creating temporary file self . file = QTemporaryFile() self . file . open () self .dictionary = DictWithPWL( "en_US" , ....... |
Also when I invoke the file with python3 I get an error on the line:
1 |
self .speller = SpellCheckWrapper( self .getWords(), self .addToDictionary) |
Could someone explain or provide some context for the use of -> and the error I see?