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

Use serial comma in 'natural_list' output by default, and allow optional omission #211

Open
bignose-debian opened this issue Oct 6, 2024 · 5 comments

Comments

@bignose-debian
Copy link

bignose-debian commented Oct 6, 2024

The 'natural_list' behaviour hard-codes the omission of serial comma in the formatted output.

To reduce ambiguity in the normal case, the serial comma should be default.

Expected:

>>> humanize.natural_list([1, 2, 3, 4, 5])
'1, 2, 3, 4, and 5'

To allow the caller to choose the non-default omission of serial comma, a keyword-only parameter should be added to specify this.

Expected:

>>> humanize.natural_list([1, 2, 3, 4, 5], serial_comma=True)
'1, 2, 3, 4, and 5'
>>> humanize.natural_list([1, 2, 3, 4, 5], serial_comma=False)
'1, 2, 3, 4 and 5'

(The “serial comma” is sometimes known as the “Oxford comma”.)

@bignose-debian
Copy link
Author

bignose-debian commented Oct 6, 2024

In my personal fork repository I have created a branch /wip/issue/211/natural-list-serial-comma that addresses this issue.

The change that implements this is the head of that branch, with preceding commits that re-factor the code to prepare for that change.

The branch includes test cases, and currently merges cleanly to 'main' branch.

@hugovk
Copy link
Member

hugovk commented Oct 6, 2024

Do you need this and intend to use it, or are you just adding it for completeness?

Let's not change the default, that's a breaking change.

Do you want to open a PR here on GitHub?

@bignose-debian
Copy link
Author

bignose-debian commented Oct 6, 2024 via email

@hugovk
Copy link
Member

hugovk commented Oct 6, 2024

My intention is to have the default set now, because I believe it was incorrectly set (and without consideration of the serial comma).

I considered it:

We could also have an input parameter to choose whether to use Oxford commas (a, b, and c) or AP style (a, b and c). And maybe to also change the "and" to "or" or something else. But let's defer those for followups if there's actual demand for it.

#103 (comment)

Both the issue and PR were open for ~18 months and no-one requested it.


The patches can be applied directly by Git, or you can merge from my fork repository <URL: https://git.sr.ht/~bignose/python-humanize/> as a remote.

Sure, but it's not just about Git. I don't want to apply it directly without running the CI or reviewing it here.

@bignose-debian
Copy link
Author

bignose-debian commented Oct 6, 2024 via email

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

No branches or pull requests

2 participants