Skip to content

[trlc] add support for nested packages - #206

Open
hoe-jo wants to merge 1 commit into
mainfrom
joho_enable_nested_packages
Open

[trlc] add support for nested packages#206
hoe-jo wants to merge 1 commit into
mainfrom
joho_enable_nested_packages

Conversation

@hoe-jo

@hoe-jo hoe-jo commented Jun 30, 2026

Copy link
Copy Markdown
Contributor
  • extent functionality
  • add documentation
  • add tests

#42

@hoe-jo
hoe-jo requested a review from a team as a code owner June 30, 2026 07:20
@hoe-jo
hoe-jo force-pushed the joho_enable_nested_packages branch 2 times, most recently from 0248a13 to 2c892e5 Compare June 30, 2026 08:38
- extent functionality
- add documentation
- add tests
@kedarnn
kedarnn force-pushed the joho_enable_nested_packages branch from 2c892e5 to 2271930 Compare August 11, 2026 06:17
Comment thread trlc/ast.py
self.items = []
self.package = None
self.imports = None
self.wildcard_roots = set()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

imports starts as None and has a safety check:
assert self.imports is not None # crash if someone forgets to call resolve_imports

However, wildcard_roots starts as an empty set() rather than None. This means that if a method uses wildcard_roots before resolve_imports() has been called, it will silently behave as though there are no wildcard roots, potentially returning incorrect results instead of failing clearly.

I’m not 100% sure whether this is intentional, but it seems inconsistent with the safety check for imports. Should wildcard_roots also be initialized to None and checked before use?

Comment thread trlc/ast.py
# covers the current package is permitted: the current package
# stays implicitly visible (Wildcard_Self_Cover).
if name == self.package.name and not is_wildcard:
mh.error(location,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I guess we need to add an explanation for this error.

Comment thread trlc/ast.py
try:
a_import = stab.lookup(mh, t_import, Package)
self.imports.add(a_import)
a_import.set_ast_link(t_import)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is important code. In the older code, it goes to the definition. Should we need to document to the changelog?

Comment thread trlc/parser.py
else:
return name, None, None

def parse_dotted_name(self):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

please add a proper docstring.

Comment thread trlc/trlc.py
for root in parser.cu.wildcard_roots:
for other in self.stab.values(ast.Package):
if other.name == pkg_name:
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this code skips the current package but what about child package
suggestion: if other.name == pkg_name or other.name.startswith(pkg_name + "."):
continue

Comment thread trlc/trlc.py
continue
if other.name == root.name or \
other.name.startswith(root.name + "."):
graph[(pkg_name , kind)].add((other.name , kind))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

extra space before ,

Comment thread trlc/trlc.py
# lobster-trace: LRM.Wildcard_Import
# lobster-trace: LRM.Wildcard_Self_Cover
if parser.cu.wildcard_roots:
for root in parser.cu.wildcard_roots:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It checks all packages again for every wildcard and every file. In a large project, this can be slow. It would be more efficient to build the package list once before the loop.

like below:
all_packages = list(self.stab.values(ast.Package))
for root in parser.cu.wildcard_roots:
for other in all_packages:

Please check its correct way or not

Comment thread trlc/lint.py
return raw_loc
return None

def _import_in_markup(self, file, item, include_descendants = False):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

no spaces around = in default parameter values

Comment thread trlc/lint.py
continue
if self._import_in_markup(file, item):
continue
imp_location = self._find_import_location(cu, item.name, False)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

no spaces around = in default parameter values

def error_messages(self):
return [m for k, m in self.messages if k in (Kind.SYS_ERROR, Kind.USER_ERROR)]

def clear(self):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This method is not sued anywhere in the test file

@SurajBDeore

Copy link
Copy Markdown

The existing nested-packages-wildcard-self-cover only tests a sibling foo.baz It doesn't test when the self-covering wildcard package also has its own child.

@SurajBDeore

Copy link
Copy Markdown

The LRM explicitly says: "importing foo.bar does NOT give you access to foo" This is a fundamental rule that has no dedicated test.
Right now this is not tested. A user could mistakenly think that importing a child also exposes the parent.
Expected output: An error

@SurajBDeore

Copy link
Copy Markdown

Every new mh.error(), mh.warning(), and mh.check() call added in this PR is missing the explanation= argument.

The project rule (copilot-instructions.md) says:

For user-facing diagnostics, do not leave explanation as None unless there is truly no actionable guidance possible. Prefer explanations that help users fix the issue.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants