Python Forum
meaning of -> syntax in function definition
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
meaning of -> syntax in function definition
#1
Hi,

I came across the following function:

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",
          .......
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:

self.speller = SpellCheckWrapper(self.getWords(), self.addToDictionary)
TypeError: 'type' object is not subscriptable

Could someone explain or provide some context for the use of -> and the error I see?
Reply


Messages In This Thread
meaning of -> syntax in function definition - by DrakeSoft - Apr-08-2022, 03:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  class definition and problem with a method HerrAyas 2 425 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  Unable to understand the meaning of the line of code. jahuja73 0 448 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  mutable argument in function definition akbarza 1 612 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  error occuring in definition a class akbarza 3 915 Nov-26-2023, 09:28 AM
Last Post: Yoriz
  determine parameter type in definition function akbarza 1 704 Aug-24-2023, 01:46 PM
Last Post: deanhystad
  [split] Explain the python code in this definition Led_Zeppelin 1 834 Jan-13-2023, 10:20 PM
Last Post: deanhystad
  [Solved] unkown (to me) function def parm "name1:name2" syntax. MvGulik 5 1,253 Nov-11-2022, 11:21 AM
Last Post: MvGulik
  Explain the python code in this definition Led_Zeppelin 1 1,205 Oct-27-2022, 04:04 AM
Last Post: deanhystad
  Csv writer meaning of quoting mg24 2 1,290 Oct-01-2022, 02:16 PM
Last Post: Gribouillis
Star I'm getting syntax error while using input function in def. yecktmpmbyrv 1 2,088 Oct-06-2021, 09:39 AM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020