Fix exception chaining
I recently went over PyTorch and Detectron2, suggesting a fix in the way that Python 3's exception chaining is used.
As described in detail in this article, exception chaining (PEP 3134) can be used to make exceptions more user-friendly, and in that case, the syntax raise new_exception from old_exception needs to be used.
When raise .. from .. is used, there will be a line saying The above exception was the direct cause of the following exception between tracebacks. However, when implicitly chaining exceptions (meaning when raise .. from .. is not used), the message will be During handling of the above exception, another exception occurred which can confuse users.
Specifically, the following should be used in order to chain exceptions:
try:
    something_which_raises_OldError
except OldError as e:
    raise NewError("A more user-friendly exception message.") from e 
instead of:
try:
    something_which_raises_OldError
except OldError:
    raise NewError("A more user-friendly exception message.")
One example which needs to be fixed is:

  
    
      pytorch-lightning/pytorch_lightning/utilities/parsing.py
    
    
        Lines 159 to 162
      in
      3d76f60
    
  
  
    

        
          
           try: 
        

        
          
               return self[key] 
        

        
          
           except KeyError: 
        

        
          
               raise AttributeError(f'Missing attribute "{key}"') 
        
    
  


If this suggestion sounds good and reasonable, I'd be happy to create a PR! Let me know your thoughts on this!