1

I'm fixing up some code in an old repo and I need to get some (mypy) tests passing. Mypy doesn't seem to recognise dash.Dash calls, throwing the following: error: Module has no attribute "Dash".

A simple fix I've found is to use dash.dash.Dash which seems to be equivalent as they have the same source file. I was wondering:

  1. Are they equivalent? If yes why have both? If no what is another solution?
  2. Why does mypy throw this error?

Apologies if it is obvious - I've never used Dash I'm merely fixing someone else's code. My Python, Mypy and Dash versions are 3.8, 0.812 and 1.21.0 respectively.

j-hil
  • 115
  • 10
  • 1
    They are the same thing, the canonical way to use it is `dash.Dash`. It's being made available in https://github.com/plotly/dash/blob/dev/dash/__init__.py#L33. Mypy should be able to pick it up, not sure what's going on here. – 0x26res Jun 07 '22 at 09:32
  • 1
    Please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example), it will be way easier for us to help you – Marius ROBERT Jun 07 '22 at 09:32
  • @MariusROBERT Its occurring on my work machine, but I've struggled to reproduce it in a controlled environment on my own PC. I'll update the question if I get anywhere. – j-hil Jun 07 '22 at 09:54
  • `dash.Dash` does not work, because it is not explicitly exported in `dash/__init__.py` (not in `__all__` and not `import Dash as Dash`). However, `dash` does not have stubs and is type annotated only slightly, so it is not suitable for use in strictly typed context. If the only typing problem you have is `Dash` import, it would be great to submit a PR, adding `__all__` [here](https://github.com/plotly/dash/blob/dev/dash/__init__.py) (and removing `noqa` for unused imports). – STerliakov Jun 09 '22 at 10:16
  • @SUTerliakov Not sure that's right - I got it working with just `dash.Dash` in the end. I think the problem was something to do with a folder in the project which was also called `dash` confusing Mypy. Adding a `__init__.py` file to the `dash` folder seemed to resolve the issue but I haven't been able to reproduce the original issue since so to any future readers: don't bank on that solution. – j-hil Jun 10 '22 at 23:56

0 Answers0