Skip to content

MAINT Use set literals#9531

Closed
rth wants to merge 1 commit intoscipy:masterfrom
rth:set-litterals
Closed

MAINT Use set literals#9531
rth wants to merge 1 commit intoscipy:masterfrom
rth:set-litterals

Conversation

@rth
Copy link
Copy Markdown
Contributor

@rth rth commented Nov 24, 2018

Set literals (and set comprehension) were added in Python 2.7. They are a bit more readable and faster than alternative methods for set creation. This uses them when possible.

@rth rth changed the title MAINT Use set litterals MAINT Use set literals Nov 24, 2018
@rgommers
Copy link
Copy Markdown
Member

I'm -0.5 on this one, hurts readability. set() is strictly clearer than {}, which many people are going to guess creates a dict.

Will wait for comments of other maintainers, but inclined to close this one. Thanks though @rth

@ilayn
Copy link
Copy Markdown
Member

ilayn commented Nov 24, 2018

I am also -0. The curly braces have almost become synonymous with dicts. As far as I can see there is not much performance gain with this either (I couldn't detect any workhorse that needs optimization).

@rth
Copy link
Copy Markdown
Contributor Author

rth commented Nov 24, 2018

Thanks for the feedback. Yes, I agree that the {} notations for sets is somewhat confusing, still, that's the native way to define sets in Python (instead of set(<list>) which does some overhead iterations etc). CPython documentation for sets uses this notation. I feel part of the issue is that sets are generally little used (compared to dicts).

Closing, given your comments and the fact that all of these changes are indeed not in performance sensitive parts of the code.

@rth rth closed this Nov 24, 2018
@WarrenWeckesser
Copy link
Copy Markdown
Member

Personally, I'm +1 on this--{'a', 'b'} it much cleaner than set(['a', 'b'])--but I'm not going to argue strongly for this PR now, since this is relatively minor cleanup. (But really, who can object to changing set([]) to set()?) I don't think we should object to the use of set literals in new code. The funny thing is, set literals will probably be more familiar to someone who learned Python six months ago than to someone who learned it six years ago.

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.

4 participants