I have looked at the following questions which are similar: Redeclared without usage and redeclared in PyCharm.
So what I'm asking here is what do you do about a "redeclared above without usage" when any of the solutions suggested cause the program to not work.
Case in point, you can take the examples from OpenAI docs as such:
import gym
env = gym.make('CartPole-v0')
for i_episode in range(20):
observation = env.reset()
for t in range(100):
env.render()
print(observation)
action = env.action_space.sample()
observation, reward, done, info = env.step(action)
if done:
print("Episode finished after {} time steps.".format(t+1))
break
It's the line 6 above (observation = env.reset()
) that, in PyCharm or IntelliJ, provides the warning:
Redeclared 'observation' defined above without usage
I realize it's just a warning and I can ignore it but none of the solutions I've found allow me to get rid of this warning. For example, moving the offending line out of the loops is no good. If you do that, the program ceases to work correctly.
I'm hoping to level up my Python skills a bit by handling warnings like this. So far my searching for this particular one has provided only examples that cause the code to break. But searching has also indicated that I probably should work to remove this warning because it can be indicative of code that leads to hard-to-find bugs later on.