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

Another attempt at fixing the collections.abc issue for Python 3.13 #2665

Merged
merged 9 commits into from
Dec 24, 2024

Conversation

DanielNoord
Copy link
Collaborator

@DanielNoord DanielNoord commented Dec 23, 2024

Well, #2658 did not work.

Let's try to fix pylint-dev/pylint#10112 again with a new fix.
It is basically the same fix as last time, but this time with some more try ... except and changing the order around. First do the normal logic, then try the frozen module logic.

Note that this targets the 3.3.x branch as I couldn't get the CI of pylint to pass from the 4.x branch. Since this needs to be back ported anyway I think that is fine.

Copy link

codecov bot commented Dec 23, 2024

Codecov Report

Attention: Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.19%. Comparing base (f79f2b4) to head (11cf784).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
astroid/interpreter/_import/spec.py 95.45% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2665      +/-   ##
==========================================
- Coverage   93.21%   93.19%   -0.02%     
==========================================
  Files          93       93              
  Lines       11083    11088       +5     
==========================================
+ Hits        10331    10334       +3     
- Misses        752      754       +2     
Flag Coverage Δ
linux 93.09% <95.45%> (-0.01%) ⬇️
pypy 93.19% <95.45%> (-0.02%) ⬇️
windows 93.19% <95.45%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
astroid/interpreter/_import/spec.py 97.24% <95.45%> (-0.41%) ⬇️

... and 1 file with indirect coverage changes

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

In 3.3.6, the django submodule wasn't imported, but even with this PR it's still being imported.

(Also major 🙏 🙏 for devoting debugging time to this, much appreciated!)

astroid/interpreter/_import/spec.py Show resolved Hide resolved
@DanielNoord
Copy link
Collaborator Author

But on 3.3.5 we did import the module right? Considering 3.3.6 also didn't handle collections properly I don't think it is the right benchmark

@DanielNoord
Copy link
Collaborator Author

Never mind, of course on 3.3.5 we did not import them. That was the whole issue 😅
Not trying to find frozen modules for submodules.

I have pushed another change, let's see if this works. First default to the normal behaviour, after it, try and see if we can frozen modules.

@DanielNoord DanielNoord reopened this Dec 23, 2024
@DanielNoord DanielNoord marked this pull request as ready for review December 23, 2024 22:36
@DanielNoord DanielNoord changed the title WIP fix for 3.13 collections Another attempt at fixing the collections.abc issue for Python 3.13 Dec 23, 2024
@jacobtylerwalls
Copy link
Member

Note that this targets the 3.3.x branch as I couldn't get the CI of pylint to pass from the 4.x branch. Since this needs to be back ported anyway I think that is fine.

Thanks. Once we have a clean pylint run, let's rebase on main and follow the usual process. Around new year I was planning to cut an alpha of astroid and bring pylint up to date, sorry it hasn't happened yet. We already have a contributor who's ready to merge in the test fixes.

@DanielNoord
Copy link
Collaborator Author

Note that this targets the 3.3.x branch as I couldn't get the CI of pylint to pass from the 4.x branch. Since this needs to be back ported anyway I think that is fine.

Thanks. Once we have a clean pylint run, let's rebase on main and follow the usual process. Around new year I was planning to cut an alpha of astroid and bring pylint up to date, sorry it hasn't happened yet. We already have a contributor who's ready to merge in the test fixes.

The clean run is going now :)

I'm not sure what the usual process would be here? Can't we merge this into the maintenance branch and then resolve any issues we get with merging it into 4.x later?
That way we focus on the issue at hand (we don't have a compatible astroid version) and can worry about future versions later.

ChangeLog Show resolved Hide resolved
Comment on lines 183 to 185
# `find_spec` raises a ValueError for modules that are missing their `__spec__`
# attributes. We don't really understand why, but this is likely caused by
# us re-implementing the import behaviour but not correctly.
Copy link
Member

Choose a reason for hiding this comment

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

Let's not make this sound mysterious: I thought it was just namespace modules (or maybe pypy) that sometimes do this, and it's good that we're catching the documented exception.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I really have no clue. The only reason I know that we need to catch this is because it was part of the stack of the original issue reporter. I still don't really know how to reproduce this case.

Copy link
Member

Choose a reason for hiding this comment

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

That's fine, but let's just remove the comment. The function is documented to raise ValueError, so let's just catch it without a comment.

spec = importlib.util.find_spec(".".join((*processed, modname)))
try:
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=Warning)
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about limiting this to UserWarning for parity with #2121?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I ran into issues with DeprecationWarnings for lib2to3 in the stdlib primer for pylint which is why I had to bump this to Warning.

Copy link
Member

Choose a reason for hiding this comment

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

Alright. It seems like a little bit of a regression that we're importing stdlib modules in more cases now, but I guess we have no choice really.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah.. I really don't know of any other way to fix this.

astroid/interpreter/_import/spec.py Show resolved Hide resolved
@jacobtylerwalls
Copy link
Member

I'm not sure what the usual process would be here? Can't we merge this into the maintenance branch and then resolve any issues we get with merging it into 4.x later?

My thought was:
Merge this into main (is there a blocker to doing this?)
Backport to 3.3.x and release 3.3.8.
Update the pylint-dev/pylint#10125 to 3.3.8

@DanielNoord DanielNoord changed the base branch from maintenance/3.3.x to main December 23, 2024 23:09
@DanielNoord
Copy link
Collaborator Author

I'm not sure what the usual process would be here? Can't we merge this into the maintenance branch and then resolve any issues we get with merging it into 4.x later?

My thought was: Merge this into main (is there a blocker to doing this?) Backport to 3.3.x and release 3.3.8. Update the pylint-dev/pylint#10125 to 3.3.8

It now targets main but that immediately causes merge conflicts...

Considering I won't have any time during Christmas I'd personally prefer to target this on the maintenance branch and just get the fix out.

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Thanks for giving me a little time to grok this, and thanks for such a diligent follow-up. Happy new year!

@jacobtylerwalls
Copy link
Member

(will reapprove after merge conflicts spruced up)

for suffix, type_ in ImportlibFinder._SUFFIXES:
file_name = modname + suffix
file_path = os.path.join(entry, file_name)
if cached_os_path_isfile(file_path):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jacobtylerwalls Bit afraid of this change... The 3.3.x branch doesn't have it so I'm not sure if this introduce more issues.

But if you approve I guess we can just try to make it work.

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Good to know, that will help me resolve the merge conflict on the backport.

@jacobtylerwalls jacobtylerwalls added this to the 3.3.8 milestone Dec 24, 2024
@jacobtylerwalls jacobtylerwalls merged commit f94e855 into pylint-dev:main Dec 24, 2024
19 of 20 checks passed
Copy link
Contributor

The backport to maintenance/3.3.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-maintenance/3.3.x maintenance/3.3.x
# Navigate to the new working tree
cd .worktrees/backport-maintenance/3.3.x
# Create a new branch
git switch --create backport-2665-to-maintenance/3.3.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f94e855268895bf995fe8eb258ea7ff7d7ccd9cf
# Push it to GitHub
git push --set-upstream origin backport-2665-to-maintenance/3.3.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-maintenance/3.3.x

Then, create a pull request where the base branch is maintenance/3.3.x and the compare/head branch is backport-2665-to-maintenance/3.3.x.

jacobtylerwalls pushed a commit to jacobtylerwalls/astroid that referenced this pull request Dec 24, 2024
…pylint-dev#2665)

* Fix issue with importing of frozen submodules

(cherry picked from commit f94e855)
jacobtylerwalls added a commit that referenced this pull request Dec 24, 2024
…ns.abc` issue for Python 3.13 (#2665) (#2666)

* Fix issue with importing of frozen submodules

(cherry picked from commit f94e855)

* Test on Python 3.13 final

* Bump CI jobs to python 3.13

---------

Co-authored-by: Daniël van Noord <[email protected]>
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Thanks a lot for handling this Daniel, amazing !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to import 'collections.abc' using python 3.13.1
3 participants