Reputation: 1
Im trying to make a statemachine in python (I know there is a module, im trying not to use those) and it is giving me an error for the reassignment, and I was wondering if I even needed to worry about it:
Expression of type "ResetState | sysCheck" cannot be assigned to member "currState" of class "Globals"
Member "set" is unknown
Type "ResetState | sysCheck" cannot be assigned to type "ResetState"
"sysCheck" is incompatible with "ResetState"PylancereportAttributeAccessIssue
So the code I have is in 2 files
Globals.py
from StateMachine import States
class Globals:
states = States()
currState = states.ResetStateObject
StateMachine.py
from Globals import Globals
class States:
def __init__(self):
self.ResetStateObject = self.ResetState()
self.sysCheckObject = self.sysCheck()
class ResetState:
def transistion_function(self):
return
def run_function(self):
return Globals.states.sysCheckObject
class sysCheck:
def transistion_function(self):
return
def run_function(self):
return Globals.states.sysCheckObject
class StateMachine:
def __init__(self):
self.new_state = Globals.states.ResetStateObject
def tick(self): ## run this in a loop to run the statemachine ||
if Globals.currState == self.new_state:
self.new_state = Globals.currState.run_function()
else:
Globals.currState = self.new_state
Globals.currState.transition_function()
The question is if I can just ignore that error
I want to assign the object of the class with the same function names, and make it simple to read in the main function
I was not able to test it, since it is supposed to run on micropython, and a lot of the supporting code is note ready yet. However I think it should be fine but I was not able to figure out myself if I need to look at classes a different way than I'm doing now
the error is on the line
Globals.currState = self.new_state
Upvotes: 0
Views: 47
Reputation: 1
I was wrond in my previous awnser, however it was fixed using enums
Upvotes: 0