Skip to content
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

[doc] language reference describes the role of module.__file__ inaccurately #65960

Closed
ericsnowcurrently opened this issue Jun 14, 2014 · 7 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir easy

Comments

@ericsnowcurrently
Copy link
Member

BPO 21761
Nosy @warsaw, @brettcannon, @ncoghlan, @ericsnowcurrently, @iritkatriel, @AlexWaygood, @slateny, @Vidhyavinu
PRs
  • bpo-21761: Clarify __file__/__cached__ in import reference #31565
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2014-06-14.20:33:24.791>
    labels = ['easy', '3.11', '3.9', '3.10', 'docs']
    title = '[doc] language reference describes the role of module.__file__ inaccurately'
    updated_at = <Date 2022-02-28.16:26:50.953>
    user = 'https://github.com/ericsnowcurrently'

    bugs.python.org fields:

    activity = <Date 2022-02-28.16:26:50.953>
    actor = 'vidhya'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation']
    creation = <Date 2014-06-14.20:33:24.791>
    creator = 'eric.snow'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 21761
    keywords = ['patch', 'easy']
    message_count = 7.0
    messages = ['220578', '407721', '407866', '407885', '414159', '414160', '414207']
    nosy_count = 9.0
    nosy_names = ['barry', 'brett.cannon', 'ncoghlan', 'docs@python', 'eric.snow', 'iritkatriel', 'AlexWaygood', 'slateny', 'vidhya']
    pr_nums = ['31565']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue21761'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @ericsnowcurrently
    Copy link
    Member Author

    The language reference [1] says:

    Ultimately, the loader is what makes use of __file__ and/or __cached__

    This implies that loaders should use __file__ and __cached__ when loading a module. Instead loaders are meant to implement exec_module() and use the spec that's passed in.

    The entire section should have a clear note that loaders are not meant to rely a module's import-related attributes.

    [1] https://docs.python.org/3/reference/import.html#__file__
    [2] https://docs.python.org/3/reference/import.html#import-related-module-attributes

    @ericsnowcurrently ericsnowcurrently added the docs Documentation in the Doc dir label Jun 14, 2014
    @iritkatriel
    Copy link
    Member

    Would it suffice to change

    "Ultimately, the loader is what makes use of __file__ and/or __cached__"

    to

    "Ultimately, the loader set the values of __file__ and/or __cached__"

    ?

    @iritkatriel iritkatriel added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes labels Dec 5, 2021
    @iritkatriel iritkatriel changed the title language reference describes the role of module.__file__ inaccurately [doc] language reference describes the role of module.__file__ inaccurately Dec 5, 2021
    @brettcannon
    Copy link
    Member

    "Ultimately, the loader set the values of __file__ and/or __cached__"

    Change it to "sets" and +1 from me!

    @ericsnowcurrently
    Copy link
    Member Author

    The key point is that loaders should be using the spec, not any of the module attrs (like __file__ and __cached__), nor setting them.

    For the specific paragraph I referenced, it would look more like:

    It is also appropriate to set __cached__ when __file__ is not set.
    However, that scenario is quite atypical. Ultimately, __file__ and
    __cached__ are set by the import system from the module spec provided
    by the finder. The spec instructs the loader. If a loader can load
    from a cached module but otherwise does not load from a file, that
    atypical scenario may be appropriate.

    @Vidhyavinu
    Copy link
    Mannequin

    Vidhyavinu mannequin commented Feb 27, 2022

    If this is still open, I would like to work on this. Please let me know.

    @AlexWaygood
    Copy link
    Member

    Hi Vidhya — @slateny submitted a PR for this issue only two days ago (you can see that it's linked to this BPO issue in the "Pull Requests" field). I think it would be good to wait until that has been reviewed before doing any work on a possible PR for this issue :)

    If you'd like to help out with this issue, you'd of course be very welcome to submit a review for @slateny's patch.

    @Vidhyavinu
    Copy link
    Mannequin

    Vidhyavinu mannequin commented Feb 28, 2022

    Thanks Alex. I will look into @slateny's patch.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @slateny slateny closed this as completed May 15, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir easy
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants