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

🔧 Export plugins explicitly with __all__ #91

Merged
merged 2 commits into from
Jun 15, 2023

Conversation

llimllib
Copy link
Contributor

According to this: microsoft/pyright#2277, pyright expects that imports are private unless they are aliased, and they will give an error if you import them.

This PR gives all imports an alias to mark them as exported.

This comes from my project where I import some plugins as:

from mdit_py_plugins.anchors import anchors_plugin
from mdit_py_plugins.dollarmath import dollarmath_plugin
from mdit_py_plugins.footnote import footnote_plugin
from mdit_py_plugins.front_matter import front_matter_plugin

and get errors like this:

$ .venv/bin/pyright                                                                                                                                                                               9:24AM

added 1 package, and audited 2 packages in 3s

found 0 vulnerabilities
/Users/llimllib/code/obsidian_notes/run.py
  /Users/llimllib/code/obsidian_notes/run.py:20:37 - error: "anchors_plugin" is not exported from module "mdit_py_plugins.anchors"
    Import from "mdit_py_plugins.anchors.index" instead (reportPrivateImportUsage)
  /Users/llimllib/code/obsidian_notes/run.py:21:40 - error: "dollarmath_plugin" is not exported from module "mdit_py_plugins.dollarmath"
    Import from "mdit_py_plugins.dollarmath.index" instead (reportPrivateImportUsage)
  /Users/llimllib/code/obsidian_notes/run.py:22:38 - error: "footnote_plugin" is not exported from module "mdit_py_plugins.footnote"
    Import from "mdit_py_plugins.footnote.index" instead (reportPrivateImportUsage)
  /Users/llimllib/code/obsidian_notes/run.py:23:42 - error: "front_matter_plugin" is not exported from module "mdit_py_plugins.front_matter"
    Import from "mdit_py_plugins.front_matter.index" instead (reportPrivateImportUsage)
4 errors, 0 warnings, 0 informations

I also removed (what seem like) unnecesssary lint comments since flake8 isn't used any longer and ruff is not flagging those imports as unused

According to this: microsoft/pyright#2277, pyright expects that imports are private unless they are aliased, and
they will give an error if you import them.

This PR gives all imports an alias to mark them as exported
@welcome
Copy link

welcome bot commented Jun 15, 2023

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, check out EBP's Code of Conduct and our Contributing Guide, as this will greatly help the review process.

Welcome to the EBP community! 🎉

@chrisjsewell
Copy link
Member

Heya, thanks, but I think perhaps the better way to signal public imports is with __all__, e.g.

from .index import plugin

__all__ = ("plugin",)

@llimllib
Copy link
Contributor Author

Sure, I've got no preference. I'll change them to that

@llimllib llimllib changed the title Alias exports to mark them as exported Export plugin symbols explicitly with __all__ Jun 15, 2023
@chrisjsewell chrisjsewell changed the title Export plugin symbols explicitly with __all__ 🔧 Export plugins explicitly with __all__ Jun 15, 2023
@chrisjsewell chrisjsewell merged commit ba0c31e into executablebooks:master Jun 15, 2023
@welcome
Copy link

welcome bot commented Jun 15, 2023

Congrats on your first merged pull request in this project! 🎉
congrats

Thank you for contributing, we are very proud of you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants