Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
FoldedCase: Improve split() compatibility
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Loading branch information
andersk committed Aug 26, 2021
commit 53e1a5354fb6590f2f1b8db6d9b5fc0cd8fdbcc3
7 changes: 6 additions & 1 deletion importlib_metadata/_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class FoldedCase(str):
>>> s.split('O')
['hell', ' w', 'rld']

>>> s.split()
['hello', 'world']

>>> sorted(map(FoldedCase, ['GAMMA', 'alpha', 'Beta']))
['alpha', 'Beta', 'GAMMA']

Expand Down Expand Up @@ -94,6 +97,8 @@ def lower(self):
def index(self, sub):
return self.lower().index(sub.lower())

def split(self, splitter=' ', maxsplit=0):
def split(self, splitter=None, maxsplit=0):
if splitter is None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change may deserve its own issue. Since it's changing the interface, it may even require a deprecation. It may be sufficient to simply provide more test coverage of this behavior.

@andersk andersk Aug 26, 2021 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This change is in its own commit that adds test coverage. I assumed the goal was compatibility with str, but if you’d prefer to keep strict backwards compatibility with old versions of FoldedCase, we could leave splitter=' ' as the default?

return super().split()
pattern = re.compile(re.escape(splitter), re.I)
return pattern.split(self, maxsplit)