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

Added missing inline types for public api #7068

Merged
merged 4 commits into from Sep 8, 2022

Conversation

Avasam
Copy link
Contributor

@Avasam Avasam commented Sep 5, 2022

Added type stubs for the generated / fake-module pyi_splash.

I've also completed inline types for all the modules meant to be used in code. So that type checkers don't see the arguments or return types as fully Unknown. Taken from:

I mostly typed function params and class attributes. Then let type inference do the heavy lifting for return types.

To help validate the types, this was first run against TypeShed's CI: Avasam/typeshed#1 (then simplified to their base and non generic types).

image
image

Avasam added a commit to Avasam/AutoSplit that referenced this pull request Sep 5, 2022
Copy link
Member

@bwoodsend bwoodsend left a comment

Choose a reason for hiding this comment

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

Uh oh, the wave of typing has hit PyInstaller. Warning in advance, I really dislike typing for Python so whilst I'm happy for the public API to gain basic (i.e. datas: list rather than datas: List[Tuple[Union[str, os.PathLike], str]]) hints to make IDEs smarter, I don't want it anywhere else and I don't want mypy or any derivatives in PyInstaller.

Can I ask that you remove types for the stuff listed in __all__s - they're not public API. In particular, this change shouldn't touch any of the hooks (PyInstaller/hooks/hook-*.py) or modulegraph (PyInstaller/lib/modulegraph). Likewise with anything in PyInstaller.utils.hooks and Pyinstaller.compat that isn't documented (and yes, I know our public/private API scoping is a mess). Can I also ask that you resist the urge to reformat the copyright headers and leave import order alone.

@Avasam Avasam force-pushed the py.typed branch 4 times, most recently from f937e6b to a8f12a8 Compare September 6, 2022 18:43
@Avasam
Copy link
Contributor Author

Avasam commented Sep 6, 2022

I was still midway through configuring my editor for this project (like changing the autoformatter from autopep8 to yapf, disabling import sorting, etc.). And I wanted to see what I had to deal with for PyInstaller's CI. So those unrelated change were not intended to stay.

Thanks for the fair warning nonetheless. I've made sure to not use any type var or generic type argument. So any type added is Python 3.7 compatible, directly inlined and at its simplest (other than unions), although partial and incomplete.
I'll simply have separate stubs and keep this library as non-py.typed .

@Avasam Avasam marked this pull request as ready for review September 6, 2022 18:43
@Avasam Avasam force-pushed the py.typed branch 2 times, most recently from 0951410 to 14a8440 Compare September 6, 2022 18:59
PyInstaller/compat.py Outdated Show resolved Hide resolved
PyInstaller/compat.py Outdated Show resolved Hide resolved
PyInstaller/compat.py Outdated Show resolved Hide resolved
@Avasam Avasam changed the title py.typed and Added missing inline types for public api Added missing inline types for public api Sep 6, 2022
@@ -146,7 +147,7 @@ def generate_parser() -> _PyiArgumentParser:
return parser


def run(pyi_args=None, pyi_config=None):
def run(pyi_args: list | None = None, pyi_config: dict | list | None = None):
Copy link
Member

Choose a reason for hiding this comment

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

pyi_config isn't allowed to be a list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically it can be an Iterable[tuple[str, object]] (as it's used to update a dict). But as you mentioned in another comment, doesn't mean that's what it's intended for. So I've updated it and other annotations meant to update CONF as well.

@@ -746,7 +757,7 @@ def is_module_or_submodule(name, mod_or_submod):
]


def collect_dynamic_libs(package, destdir=None):
def collect_dynamic_libs(package: str, destdir: object | None = None):
Copy link
Member

Choose a reason for hiding this comment

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

destdir should be a string rather than an arbitrary object.

def collect_data_files(
package: str,
include_py_files: bool = False,
subdir: str | bytes | os.PathLike | None = None,
Copy link
Member

Choose a reason for hiding this comment

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

Can we just eliminate bytes from all filename type annotations. We never intend these functions to work with bytes.

PyInstaller/compat.py Outdated Show resolved Hide resolved
pyi_splash-stubs/__init__.pyi Outdated Show resolved Hide resolved
@Avasam Avasam requested a review from rokm September 7, 2022 22:18
@bwoodsend bwoodsend merged commit bf2a4ad into pyinstaller:develop Sep 8, 2022
@Avasam Avasam deleted the py.typed branch September 8, 2022 07:38
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants