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

Re-enable mypy and sync mypy.ini from skeleton #4604

Merged
merged 3 commits into from
Oct 17, 2024

Conversation

Avasam
Copy link
Contributor

@Avasam Avasam commented Aug 27, 2024

Summary of changes

Ref jaraco/skeleton#143

Pull Request Checklist

mypy.ini Show resolved Hide resolved
@Avasam
Copy link
Contributor Author

Avasam commented Aug 27, 2024

The "Fix ConfigHandler generic" commit is related to python/mypy#17631 (comment) (same symptoms). Not sure why it wasn't failing before, didn't fail locally (granted I'm running from Windows on 3.9, so it could be environment-specific, despite version/platform flags), and only failed on the CI on (MacOS and/or 3.12)1.

But it still revealed an underlying misuse of the TypeVar

Footnotes

  1. No other MacOS or Python 3.12 action had time to complete, so idk which one was the specific cause.

@Avasam Avasam changed the title Re-enable mypy Re-enable mypy and sync mypy.ini from skeleton Aug 27, 2024
@Avasam Avasam requested a review from jaraco August 27, 2024 16:55
@jaraco
Copy link
Member

jaraco commented Aug 27, 2024

I still see some test failures.

_________________________ setuptools/config/expand.py __________________________
[gw3] linux -- Python 3.10.14 /home/runner/work/setuptools/setuptools/.tox/py/bin/python
206: error: "type: ignore" comment without error code (consider "type: ignore[union-attr]" instead)  [ignore-without-code]
291: error: "type: ignore" comment without error code (consider "type: ignore[assignment]" instead)  [ignore-without-code]
362: error: "type: ignore" comment without error code (consider "type: ignore[call-overload]" instead)  [ignore-without-code]
______________________ setuptools/config/pyprojecttoml.py ______________________
[gw3] linux -- Python 3.10.14 /home/runner/work/setuptools/setuptools/.tox/py/bin/python
48: error: "type: ignore" comment without error code (consider "type: ignore[union-attr]" instead)  [ignore-without-code]
__________________________ pkg_resources/__init__.py ___________________________
[gw0] linux -- Python 3.10.14 /home/runner/work/setuptools/setuptools/.tox/py/bin/python
2780: error: "type: ignore" comment without error code (consider "type: ignore[arg-type]" instead)  [ignore-without-code]
__________________ setuptools/tests/test_editable_install.py ___________________
[gw2] linux -- Python 3.10.14 /home/runner/work/setuptools/setuptools/.tox/py/bin/python
881: error: "type: ignore" comment without error code (consider "type: ignore[index]" instead)  [ignore-without-code]
883: error: "type: ignore" comment without error code (consider "type: ignore[index]" instead)  [ignore-without-code]
891: error: "type: ignore" comment without error code (consider "type: ignore[index]" instead)  [ignore-without-code]
892: error: "type: ignore" comment without error code (consider "type: ignore[index]" instead)  [ignore-without-code]

What's the plan for those?

Also, thanks for reconciling the differences between setuptools' and skeleton's mypy.ini.

@Avasam
Copy link
Contributor Author

Avasam commented Aug 27, 2024

I still see some test failures.
What's the plan for those?

I rebase and fix them 😃

setuptools/config/expand.py Outdated Show resolved Hide resolved
setuptools/config/expand.py Outdated Show resolved Hide resolved
Comment on lines 364 to 365
# TODO: Explain why passing None is fine here when ConfigParser.default_section expects to be str
parser = ConfigParser(default_section=None, delimiters=("=",)) # type: ignore[call-overload]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could this be ?

Suggested change
# TODO: Explain why passing None is fine here when ConfigParser.default_section expects to be str
parser = ConfigParser(default_section=None, delimiters=("=",)) # type: ignore[call-overload]
parser = ConfigParser(default_section="", delimiters=("=",))

Copy link
Member

Choose a reason for hiding this comment

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

The meaning of default_section is documented here. It suggests that the default section could be overridden from the default of "DEFAULT".

I don't know why the original author passed default_section=None. Reading briefly through the configparser code, it looks like the default_section is often compared for equality, so None is effectively treated as "no default". Presumably that was the intention of this usage.

Probably what should happen here is configparser should be explicit about what types are allowed here. I scanned through the configparser tests, but didn't see anything that explicitly allowed or excluded None as a valid type, and since None appears to be valid per this usage, it's probably more accurately an Any or Hashable type.

My recommendation - file a ticket with python/cpython (or python/typeshed) indicating that the type spec for this parameter is ambiguous and should be refined, and then link that issue here instead of a TODO (since there's nothing "to do" in setuptools until such a refinement is present).

Copy link
Contributor Author

@Avasam Avasam Sep 27, 2024

Choose a reason for hiding this comment

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

The author being @abravalheri in https://github.com/pypa/setuptools/pull/3067/files#diff-2e8e2332e00f145022b07f1a5de895e643f38570a1765bd2da26e27fe29b64cdR305 I'll ask even if that was a couple years ago :)

Do you remember if there was any reason to set ConfigParser's default_section to None instead of using the default of "DEFAULT" ? (re-exported as configparser.DEFAULTSECT)

(I'm still gonna go ask whether using None is a valid usage. Seemingly to avoid having default sections)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the mean time, I marked setuptool's usage as undocumented behaviour, linking to his issue/question I created: python/typeshed#12700

Further actions can come in a follow-up PR once the question is resolved and an action has been taken.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you remember if there was any reason to set ConfigParser's default_section to None instead of using the default of "DEFAULT" ? (re-exported as configparser.DEFAULTSECT)

I believe I was trying to achieve the behaviour described by Jason, i.e. "no default".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abravalheri Thanks. This confirms what we thought. I think the new comment of calling this out as undocumented behaviour but not changing it is probably fine.

@@ -1418,7 +1418,7 @@ def VCRuntimeRedist(self) -> str | None:
os.path.join(prefix, arch_subdir, crt_dir, vcruntime)
for (prefix, crt_dir) in itertools.product(prefixes, crt_dirs)
)
return next(filter(os.path.isfile, candidate_paths), None)
return next(filter(os.path.isfile, candidate_paths), None) # type: ignore[arg-type] #python/mypy#12682
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Avasam
Copy link
Contributor Author

Avasam commented Sep 26, 2024

@jaraco Bump on this since currently static typing validation from mypy is disabled (at least pyright's running). And some of my pending PRs should be validated by it.

Copy link
Member

@jaraco jaraco left a comment

Choose a reason for hiding this comment

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

LGTM. Just a couple lingering concerns.

setuptools/config/expand.py Outdated Show resolved Hide resolved
Comment on lines 364 to 365
# TODO: Explain why passing None is fine here when ConfigParser.default_section expects to be str
parser = ConfigParser(default_section=None, delimiters=("=",)) # type: ignore[call-overload]
Copy link
Member

Choose a reason for hiding this comment

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

The meaning of default_section is documented here. It suggests that the default section could be overridden from the default of "DEFAULT".

I don't know why the original author passed default_section=None. Reading briefly through the configparser code, it looks like the default_section is often compared for equality, so None is effectively treated as "no default". Presumably that was the intention of this usage.

Probably what should happen here is configparser should be explicit about what types are allowed here. I scanned through the configparser tests, but didn't see anything that explicitly allowed or excluded None as a valid type, and since None appears to be valid per this usage, it's probably more accurately an Any or Hashable type.

My recommendation - file a ticket with python/cpython (or python/typeshed) indicating that the type spec for this parameter is ambiguous and should be refined, and then link that issue here instead of a TODO (since there's nothing "to do" in setuptools until such a refinement is present).

@Avasam
Copy link
Contributor Author

Avasam commented Sep 30, 2024

Other PRs started failing too with a strange error (not the same though), so CI failure may or may not be related to these changes (although I don't see which of my changes could cause it)

@Avasam Avasam force-pushed the re-enable-mypy branch 3 times, most recently from fbdb2b2 to ec54219 Compare October 15, 2024 16:22
@Avasam
Copy link
Contributor Author

Avasam commented Oct 15, 2024

Now that the weird CI issue seems resolved. I'd like to merge this before bumping mypy to 1.12. And to unblock #4504

@abravalheri abravalheri merged commit 89b4401 into pypa:main Oct 17, 2024
23 of 25 checks passed
@Avasam Avasam deleted the re-enable-mypy branch October 17, 2024 14:36
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.

3 participants