pytorch-lightning: [Pyright] Cannot access member 'X' for type 'None'

Pyright raises 89 errors on master about Cannot access member 'X' for type 'None'. Here is an example in evaluation_loop.py:

                # track outputs for collation
                dl_outputs.append(output)

                # batch done
                if test:
                    self.test_progress_bar.update(1)  # PYRIGHT ERROR
                else:
                    self.val_progress_bar.update(1)  # PYRIGHT ERROR
                    self.main_progress_bar.update(1)  # PYRIGHT ERROR
            outputs.append(dl_outputs)

        eval_results = {}

One way to fix this is to indicate the type of those variables:

self.test_progress_bar: Any = None

Unless you see a more elegant way?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (15 by maintainers)

Most upvoted comments

As discussed with @Borda, I would suggest improving the typing of all the code base to make static type checking more robust! 😃

I think that we may start with ones which are most used that e continue with others… for the most used lest doing just module by module so the PR is not pending for long… and avoid collisions

@uditarora still interested in taking this over? :]

Sure, I have some free time over the next week. Let me try and fix more Pyright errors 😃

Let me know if you have something specific in mind that I should look at. Else I can pick up some module randomly.

I’d be happy to take a look at this if no one else is working on it. Let me know.

CC: @Borda

Not sure I would have time on the short term but I’ll keep it on my TODO list.