- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33.3k
gh-84013: normalize directory contents during import #113447
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
          
     Open
      
      
            ronaldoussoren
  wants to merge
  11
  commits into
  python:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
ronaldoussoren:gh-84013
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +108
        
        
          −16
        
        
          
        
      
    
  
  
     Open
                    Changes from 4 commits
      Commits
    
    
            Show all changes
          
          
            11 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      b7ba389
              
                gh-84013: normalize directory contents during import
              
              
                ronaldoussoren 7f4b01b
              
                Slightly cleaner code
              
              
                ronaldoussoren 6ea9497
              
                Argh... Previous cleanup was a bit too quick...
              
              
                ronaldoussoren c216e08
              
                Actually fix the "cleaned up" version
              
              
                ronaldoussoren 3f16ae1
              
                Change of implementation
              
              
                ronaldoussoren 80b6eec
              
                Revert accidental reordering
              
              
                ronaldoussoren b9e8927
              
                Update Lib/test/test_import/__init__.py
              
              
                ronaldoussoren 7d2d2bf
              
                Address review comment
              
              
                ronaldoussoren 18d99ae
              
                Some changes
              
              
                ronaldoussoren 985e50a
              
                Apply suggestions from code review
              
              
                serhiy-storchaka c13edc8
              
                Merge branch 'main' into gh-84013
              
              
                serhiy-storchaka File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the sake of
__import__()andimportlib.import_module()we will probably need to either normalizecache_moduleor preserve the original name in the cache. The former sounds expensive so the latter might be the way to go.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regardless, we should probably have some test cases that use one of those functions rather than syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the code to keep the unnormalised name around, we need the unnormalised name to access the filesystem and need the normalised name to compare to
tail_module(which will generally be normalised by the compiler).I agree that there should be more test cases, I started out with just the minimal test from the issue to see if I can get this to work without bootstrapping issues and get some feedback. I'll definitely add more tests when this approach is seen as acceptable by @brettcannon (as the importlib expert).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the cache always keeps the raw name then can we drop
_cache_is_normalized?