Hi Paul it's an interesting proposal. I have a couple clarifying questions
about it.

On Tue, Dec 1, 2020 at 10:32 AM Paul Sokolovsky <pmis...@gmail.com> wrote:

> Effectively, with the current Python execution model, all code is
> executed at "import-time". This proposal seeks to introduce
> well-defined distinction between import-time vs run-time. For this, it
> introduces the `__main__()` function, localted in the `__main__` module
> of the application (from which application execution starts). All
> top-level code in the `__main__` module is executed to completion,
> including code in recursively imported modules. This completes the
> "import-time" phase of the application. After that, the `__main__()`
> function is executed, which begins the "run-time' phase.
>

Two questions about this.

1. What about single module packages? If there is no __main__ module, how
does the interpreter find my __main__() function?

2. In order to maintain the distinction between "import time" and "run
time", will it be illegal to explicitly run __main__() in the __main__
module at import time? If not, would __main__() still be run (a *second
time*) at run time....?

```
__

# import time section

def __main__():
    # run time
    print("foo")

__main__()
```

Is the output:

foo
foo

...or it is just:

foo

...?


> ## Discussion and implications
>
> The baseline implications should be fairly obvious from the text above:
>
> ```
> def fun():
>     pass
>
> # This (defining the function of the same name) will lead to warning
> # at import-time.
> def fun():
>         pass
>
> import mod
>
> # This (assigning to a var in another module) is possible
> # both at import-time and run-time.
> mod.var = 1
>
> # This will lead to warning at import-time and RuntimeError at runtime.
> mod.func = lambda *a, **kw: print("Stabbed out!")
> ```
>

In the above code snippet, are you assuming that mod.func already exists,
and the last line in the module is redefining the existing mod.func, and
this is what causes the runtime error?

---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home
or actually going home." - Happy Chandler
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/C46OBXSH72W6ICLMIM3UPXR3Y6327TBU/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to