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

Improve check_party for 1st party module #592

Merged
merged 3 commits into from
May 23, 2024

Conversation

laggykiller
Copy link
Contributor

@laggykiller laggykiller commented May 23, 2024

This is the original check_party() in stubgen.py

    def check_party(self, module: str) -> Literal[0, 1, 2]:
        """
        Check source of module
        0 = From stdlib
        1 = From 3rd party package
        2 = From the package being built
        """
        if module.startswith(".") or module == self.module.__name__.split('.')[0]:
            return 2

        try:
            spec = importlib.util.find_spec(module)
        except (ModuleNotFoundError, ValueError):
            return 1

        if spec:
            if spec.origin and "site-packages" in spec.origin:
                return 1
            else:
                return 0
        else:
            return 1

See #420 (comment)

Somehow module in check_party could be my_sanitized_module.BASE instead of .my_sanitized_module or my_sanitized_module. #496 only prevent crash due to ValueError, but all those modules are all misclassified as 3rd party modules instead of 1st party. This PR improve check for such condition.

@wjakob
Copy link
Owner

wjakob commented May 23, 2024

Thanks!

@wjakob wjakob merged commit 4b376b7 into wjakob:master May 23, 2024
24 checks passed
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