Skip to content

Support __main__ #658

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

Closed
refi64 opened this issue May 9, 2015 · 10 comments
Closed

Support __main__ #658

refi64 opened this issue May 9, 2015 · 10 comments

Comments

@refi64
Copy link
Contributor

refi64 commented May 9, 2015

Right now, it says the module can't be found.

@JukkaL
Copy link
Collaborator

JukkaL commented May 12, 2015

Ah yes, I stumbled into this a while ago myself. Thanks for reporting this!

@ddfisher
Copy link
Collaborator

ddfisher commented Mar 2, 2016

@kirbyfan64 I know it's been a while, but can you be more specific about the issue you ran into here?

@refi64
Copy link
Contributor Author

refi64 commented Mar 2, 2016

I think it was import __main__.

@gvanrossum
Copy link
Member

If you're talking about code that imports __main__, I can't repro. E.g.

mypy -c 'import __main__'

passes without errors.

@ErikBjare
Copy link

@gvanrossum Put the import __main__ in a file then run mypy test_main.py.

The following will happen:

test_main.py:1: error: Cannot find module named '__main__'
test_main.py:1: note: (Perhaps setting MYPYPATH would help)

Interesting that mypy -c 'import __main__' works.

@gvanrossum
Copy link
Member

FWIW this is because when you pass module filenames (i.e. *.py) on the command line the module name is derived from the filename. So mypy test_main.py sets the module name to test_main. With -c the module name is always set to __main__. The module name is also set to __main__ if you pass a file whose extension isn't .py (or .pyi).

So I'm not even sure this counts as a bug. Certainly the legit use cases for importing __main__ are pretty limited, and mypy probably shouldn't assume it has any particular attributes.

@JukkaL
Copy link
Collaborator

JukkaL commented Apr 4, 2016

What about __main__ in a package, to run a package as a program?

@gvanrossum
Copy link
Member

gvanrossum commented Apr 4, 2016 via email

@gvanrossum
Copy link
Member

Is there a compelling use case?

@gvanrossum gvanrossum added this to the Undetermined priority milestone Apr 7, 2016
@JukkaL JukkaL removed the priority label Jun 7, 2016
@gvanrossum gvanrossum removed this from the Undetermined priority milestone Mar 29, 2017
@JukkaL
Copy link
Collaborator

JukkaL commented May 17, 2018

Closing as there don't seem to be compelling use cases.

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

No branches or pull requests

5 participants