Skip to content

gh-128720: Fix doc inacurracy about __main__.__file__ existence in the REPL #128721

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

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions Doc/library/__main__.rst
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,7 @@ Here is an example module that consumes the ``__main__`` namespace::
if not did_user_define_their_name():
raise ValueError('Define the variable `my_name`!')

if '__file__' in dir(__main__):
print(__main__.my_name, "found in file", __main__.__file__)
else:
print(__main__.my_name)
print(__main__.my_name)

Example usage of this module could be as follows::

Expand Down Expand Up @@ -330,7 +327,7 @@ status code 0, indicating success:
.. code-block:: shell-session

$ python start.py
Dinsdale found in file /path/to/start.py
Dinsdale

Note that importing ``__main__`` doesn't cause any issues with unintentionally
running top-level code meant for script use which is put in the
Expand Down Expand Up @@ -361,8 +358,5 @@ defined in the REPL becomes part of the ``__main__`` scope::
>>> namely.print_user_name()
Jabberwocky

Note that in this case the ``__main__`` scope doesn't contain a ``__file__``
attribute as it's interactive.

Comment on lines -364 to -366
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to keep this line, depending on the resolution of the issue. I agree with the changes above.

The ``__main__`` scope is used in the implementation of :mod:`pdb` and
:mod:`rlcompleter`.
Loading