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

Revised regex for magics removal #875

Merged
merged 1 commit into from
Oct 30, 2024
Merged

Revised regex for magics removal #875

merged 1 commit into from
Oct 30, 2024

Conversation

emeryberger
Copy link
Member

The previous regex (meant to eliminate Jupyter notebook 'magics'), in some edge cases, would cause parsing to fail (leading to an IndentationError). This PR updates the regex to prevent that from happening.

@emeryberger
Copy link
Member Author

Fixes #671.

@emeryberger emeryberger merged commit ad5373f into master Oct 30, 2024
22 checks passed
@emeryberger
Copy link
Member Author

For posterity: this code (from Python 3.12's socket.py) leads to the above-mentioned problem.

import _socket

class socket(_socket.socket):

    def __repr__(self):
        """Wrap __repr__() to reveal the real class name and socket                                                                                       
        address(es).                                                                                                                                      
        """
        closed = getattr(self, '_closed', False)
        s = "<%s.%s%s fd=%i, family=%s, type=%s, proto=%i" \
            % (self.__class__.__module__,
               self.__class__.__qualname__,
               " [closed]" if closed else "",
               self.fileno(),
               self.family,
               self.type,
               self.proto)

The culprit is the interaction between the backslash and the % on the following line. With the old regexp, part of this code was incorrectly transformed to the following (note that the % has been replaced by a #):

        s = "<%s.%s%s fd=%i, family=%s, type=%s, proto=%i" \
            # (self.__class__.__module__,

With the new regex, the % is correctly left unchanged.

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.

1 participant