I have some python code I'm trying to type hint PEP484 style, and getting spurious warnings.
Going through a loop, I first initialize a last_row to None.
on the first pass I give it a value, and then next time I do something with it.
However, Pylint still thinks it's None even though I declared the type as a Dict
How to avoid best this?
I thought of putting some value other than None on initialize just to shut up the linter, but this seems like a hack.
last_row: Dict = {}
Maybe the linter is pointing to a code smell and I should fix this to have a more consistent type/value for the last_row ...
last_row: Dict = None
for index, row in self.df.iterrows():
if last_row is not None:
row['intent_from'] = str(last_row['intent'])
last_row = row
in the code above I get this error:
Value 'last_row' is unsubscriptable
I believe the typescript checker is smarter about these kind of things, but it is making a runtime guess so that also feels a bit fragile.