Skip to content

module.children behavior does not match documentation (only tracks first requires) #9371

Closed
@codebling

Description

@codebling

TL;DR module.children does not behave according to documentation.

What be the expected behaviour of module.children?

Documentations states that module.children is "the module objects required by this one." This is false, as it only lists the children that were required for the first time by the module. Since module.parent is correctly documented as containing "the module that first required this one", it seems like this may be a documentation bug. If that's the case, we should correct the documentation.

Considering the issue on another level, what is the purpose of module.children and module.parent? Having a full graph of the first requires, or a partial/incomplete graph of all require relationships, does not seem at all useful to me. Why do these exist? I propose the addition of module fields requirers and requirees as respective analogues of parent and children, but ones which will keep track of all requires. The code will be essentially the same as what is currently in place, except that instead of running on module initialisation and pushing this module into the parent module's children structure (which only works the first time it is required, since after that the module is initialised and cached), we run after every require, pushing this module into the child's requirers. This will generally also only run once per uncached module (except for modules with conditional or lazy requires), except still works even if the children are cached.

So, fix options here are:

  1. consider this a documentation bug and fix the documentation
  2. change the behaviour of module.children to match the documentation (fix basically described above)

Possibly related to #7131 and #3933

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.good first issueIssues that are suitable for first-time contributors.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.moduleIssues and PRs related to the module subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions