Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mypy strict: error: Module "streamlit" does not explicitly export attribute "experimental_dialog" [attr-defined] (among others) #8712

Closed
3 of 4 tasks
wyattscarpenter opened this issue May 19, 2024 · 2 comments · Fixed by #8728
Assignees
Labels
feature:st.dialog priority:P4 status:confirmed Bug has been confirmed by the Streamlit team status:in-progress We're on it! type:bug Something isn't working

Comments

@wyattscarpenter
Copy link

wyattscarpenter commented May 19, 2024

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

Trying to use the experimental_dialog decorator at all gives an error in typechecking in mypy strict mode. (strict mode turns on no_implicit_reexport). Also in pyright as well.

The mypy error is error: Module "streamlit" does not explicitly export attribute "experimental_dialog" [attr-defined]. The pyright error is error: "experimental_dialog" is not exported from module "streamlit" (reportPrivateImportUsage)

After much staring at https://github.com/streamlit/streamlit/blob/1.34.0/lib/streamlit/__init__.py#L77 , I realized the answer is actually simple: a reexport is not explicit unless you as the variable to the same name. As mypy documentation says https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-no-implicit-reexport:

# This won't re-export the value
from foo import bar

# Neither will this
from foo import bar as bang

# This will re-export it as bar and allow other modules to import it
from foo import bar as bar

Therefore, exports like dialog_decorator as experimental_dialog are a problem, and do not serve their intended purpose.

So, you cannot rename the variable in the reexport and have it still work. But I'm pretty sure you can still put experimental_dialog = dialog_decorator in the source file, though, and then have your reexport line be

from streamlit.elements.dialog_decorator import (
  experimental_dialog as experimental_dialog
)

if you want.

P.S.: The Modules that the user should have access to. These are imported with "as" syntax pass mypy checking with implicit_reexport disabled." comment block, seems to have a typo, by the way, and also doesn't seem very useful as currently written, and also possibly is misplaced.

Reproducible Code Example

#example.py

import streamlit as st

@st.experimental_dialog("Fun example")
def f() -> None:
  st.write("This works fine, but doesn't typecheck under strict.")
f()

Steps To Reproduce

$ mypy --strict example.py
example.py:3: error: Module "streamlit" does not explicitly export attribute "experimental_dialog" [attr-defined]
$ mypy example.py
Success: no issues found in 1 source file

Expected Behavior

No response

Current Behavior

No response

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: Streamlit, version 1.34.0
  • Python version: Python 3.11.0
  • Operating System: Windows 10
  • Browser: Firefox
  • mypy: mypy 1.10.0 (compiled: yes)

Additional Information

No response

@wyattscarpenter wyattscarpenter added status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working labels May 19, 2024
Copy link

If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.

Your feedback helps us prioritize which bugs to investigate and address first.

Visits

@raethlein raethlein added status:confirmed Bug has been confirmed by the Streamlit team and removed status:needs-triage Has not been triaged by the Streamlit team labels May 21, 2024
@raethlein raethlein added the status:in-progress We're on it! label May 21, 2024
@raethlein
Copy link
Collaborator

Thanks @wyattscarpenter for the detailed issue! I have created a PR here #8728 to fix the explicit-export issue and update the comment.

raethlein added a commit that referenced this issue May 21, 2024
## Describe your changes

Closes #8712

The `experimental_dialog` directive was not exported explicitly as reported by `mypy --strict` (see also https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-no-implicit-reexport).
The PR updates the way how to import & export the `experimental_dialog`
so that `mypy --strict` stops complaining and also follows the way other
directives are re-exported such as `experimental_fragment`:

## GitHub Issue Link (if applicable)

## Testing Plan

- Manually tested locally and noted down how to automize this in the future

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:st.dialog priority:P4 status:confirmed Bug has been confirmed by the Streamlit team status:in-progress We're on it! type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants