3 ms·
The thing listed as “A Non-Functioning Alternative” seems to work correctly in both Pylance and mypy, if you add “# type: ignore” at the end of the import line.
by dragonwriter 5y ago
The thing listed as “A Non-Functioning Alternative” seems to work correctly in both Pylance and mypy, if you add “# type: ignore” at the end of the import line.
- adamchainz 5y agoUnfortunately that prevents Mypy from loading the type hints for 'markdown' from types import ModuleType markdown: ModuleType | None try: import markdown # type: ignore [no-redef] except ImportError: markdown = None if markdown is not None: reveal_type(markdown.markdown) Running Mypy: example.py:11: note: Revealed type is "Any" Whereas when correctly imported: example.py:3: note: Revealed type is "def (text: builtins.str, *, extensions: Union[typing.Sequence[Union[builtins.str, markdown.extensions.Extension]], None] =, extension_configs: Union[typing.Mapping[builtins.str, typing.Mapping[builtins.str, Any]], None] =, output_format: Union[Literal['xhtml'], Literal['html'], None] =, tab_length: Union[builtins.int, None] =) -> builtins.str"