I'm trying to make a Python module which provides functions for user input. My code looks like this:
class PyInput:
def inputString(prompt = "Enter a string: >>> "):
"""inputString asks the user to input a string."""
userInput = input(prompt)
str(userInput)
return userInput
Unfortunately, I am getting multiple errors: The first says that "Instance methods should take a "self" parameter" (I know what this means, but is there a way to not have to define a function within a class to accept a "self" parameter?)
My second error is in my testing code, which looks like this:
from PyIO import *
vartest = "mystring"
tester = PyInput.inputString(vartest)
print(tester)
and it says that:
Argument of type "Literal['Input test: >>> ']" cannot be assigned to parameter "prompt" of type "PyInput" in function "inputString"
"Literal['Input test: >>> ']" is incompatible with "PyInput"
I noticed that when I add "# type: ignore" to the lines that cause errors, my testing program runs as expected. Is there any way to fix this?
I'm using Python 3.11 on a Windows 11 64 bit laptop.
source https://stackoverflow.com/questions/74892198/receiving-errors-when-defining-functions-no-self-parameter-and-invalid-var-typ
Comments
Post a Comment