Skip to content

variables starting with an underscore are not imported with * imports even when present in __all__ #3745

Closed

Description

@daboross

Reduced example of the issue:

defs.py:

def __pragma__(arg: str) -> None:
    pass


__all__ = ["__pragma__"]

main.py:

from defs import *

__pragma__('main')

print('hi')

The current mypy behavior differs as follows:

$ python main.py
hi
$ mypy main.py
main.py:3: error: Name '__pragma__' is not defined

This is an most likely an obscure case, but if it could be added to mypy I would greatly appreciate it that would be greatly appreciated. I can also write a pull request to implement this, if it's deemed worth adding.

My use case for this is providing stubs for 'meta' functions provided by transcrypt, a Python transpiler/pre-processor. Transcrypt provides __pragma__ and __new__ to control / augment the transpilation. Having import * from defs work to import both these transcrypt-builtins and all other transpilation-builtin types would greatly increase usability of mypy and transcrypt together.

Activity

  1. added a commit that references this issue on Jul 21, 2017
    2d67784
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions