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

Modify Repository.get_contents() to always return List[github.ContentFile.ContentFile] #2199

Open
pjames5 opened this issue Mar 8, 2022 · 0 comments

Comments

@pjames5
Copy link

pjames5 commented Mar 8, 2022

Hello!

I made some recent updates to application that uses Repository.get_contents() and ran into some typing issues with a recent mypy update.

My proposal is to modify the return type of Repository.get_contents() to be List[github.ContentFile.ContentFile] instead of Union[github.ContentFile.ContentFile, List[github.ContentFile.ContentFile], None]. This would help to clean up the mypy issues and make the API clearer.

Something like this:

        if isinstance(data, list):
            return [
                # Lazy completion only makes sense for files. See discussion
                # here: https://github.com/jacquev6/PyGithub/issues/140#issuecomment-13481130
                github.ContentFile.ContentFile(
                    self._requester, headers, item, completed=(item["type"] != "file")
                )
                for item in data
            ]
        return [
            github.ContentFile.ContentFile(
                self._requester, headers, data, completed=True
            )
        ]

I'm happy to open a PR with this change or discuss further. Thanks!

@pjames5 pjames5 changed the title Modify Repository.get_contents() to always return a List[github.ContentFile.ContentFile] Modify Repository.get_contents() to always return List[github.ContentFile.ContentFile] Mar 8, 2022
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

No branches or pull requests

1 participant