executablebooks / mdit-py-plugins

Collection of core plugins for markdown-it-py
https://mdit-py-plugins.readthedocs.io
MIT License
30 stars 32 forks source link

🔧 Export plugins explicitly with `__all__` #91

Closed llimllib closed 1 year ago

llimllib commented 1 year ago

According to this: https://github.com/microsoft/pyright/issues/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

welcome[bot] commented 1 year ago

Thanks for submitting your first pull request! You are awesome! :hugs:
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! :tada:

chrisjsewell commented 1 year ago

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 commented 1 year ago

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

welcome[bot] commented 1 year ago

Congrats on your first merged pull request in this project! :tada: congrats
Thank you for contributing, we are very proud of you! :heart: