setuptools
setuptools copied to clipboard
Type `pkg_resources._declare_state` and make it work statically
Summary of changes
After playing around with previous PRs with whether _distribution_finders, _namespace_handlers and _namespace_packages definitions should be moved closer to declarations, I noticed that, since we have to define the variables for other reasons anyway, there's no point to _declare_state's global namespace shenanigans. This PR makes it work for static analysis and, after #4246 is merged, will reduce changes in #4242
Pull Request Checklist
- [ ] Changes have tests (existing tests should pass, no intended behaviour change)
- [ ] News fragment added in
newsfragments/. (even typing-wise there's no user-facing change here, it's all privates) (See documentation for details)
@Avasam, I am assuming this change does not affect https://github.com/pypa/setuptools/blob/b4b622e2100f0c2ec739f61e1113a94c40e47466/pkg_resources/init.py#L3320, because https://github.com/pypa/setuptools/blob/b4b622e2100f0c2ec739f61e1113a94c40e47466/pkg_resources/init.py#L3340 is already ensuring working_set is a global variable, right?
@Avasam, I am assuming this change does not affect
https://github.com/pypa/setuptools/blob/b4b622e2100f0c2ec739f61e1113a94c40e47466/pkg_resources/init.py#L3320
, because https://github.com/pypa/setuptools/blob/b4b622e2100f0c2ec739f61e1113a94c40e47466/pkg_resources/init.py#L3340
is already ensuring
working_setis a global variable, right?
Yep, I validated for working_set too
(BTW, would it make sense to add the annotations in this PR since it is already introducing the variable declaration?) That would probably showcase the benefits of the approach even more.
I know you've already approved the PR, but I added that change since it's small anyway on already modified lines. After #4246, as part of completely typing the register_* methods, I'll introduce some aliases (same that are already in typeshed) to avoid duplicating those Callable type definition
This change will also reduce errors in https://github.com/pypa/setuptools/pull/4246 to bring it closer to passing