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

Too clever? #133

Closed
bwohlberg opened this issue Dec 13, 2021 · 7 comments
Closed

Too clever? #133

bwohlberg opened this issue Dec 13, 2021 · 7 comments
Assignees

Comments

@bwohlberg
Copy link
Collaborator

This is a clever little construction

[shapes2.append(s) for s in shape]

but is the compactness worth the potential confusion (codefactor does not like it)? The non-obscure way of doing this only requires one extra line, i.e.

for s in shape:
    shapes2.append(s)
@FernandoDavis
Copy link
Contributor

Personally, I like the approach on the first one since it looks clean and compact. I tested the performance and there wasn't much difference perhaps get a test with huge amounts of data and see if there are any performance hits but I doubt it. I think it's readable and neat so it gets a positive vote on my end.

Also, I checked the file and neither shapes nor shapes2 is used after the example, not sure if that's a w.i.p or non-intended but thought id mention it!

@lukepfister
Copy link
Contributor

disagree with codefactor here, and i'd disagree that this is obscure; list comprehensions are the "pythonic way".

i prefer to use list comprehensions like this when it is small enough to remain on one line.

iirc in some contexts list comprehensions are much faster than for loops-- i don't think that is going to be the bottleneck here, though.

all that being said, no real objections to changing it

@bwohlberg
Copy link
Collaborator Author

I don't have very strong feelings about it either, but the most common view within the Python community seems to be that it's unpythonic, e.g. see this discussion.

@lukepfister
Copy link
Contributor

Okay, fair-- my model is typically "making a list? use a list comprehension". the point in the link is that you shouldn't apply functions with side effects inside of a list comprehension, and this is just calling .append. no list is returned.

fair enough, i'm good with changing it

@bwohlberg
Copy link
Collaborator Author

Also, I checked the file and neither shapes nor shapes2 is used after the example, not sure if that's a w.i.p or non-intended but thought id mention it!

I overlooked this until now. It appears that the entire section of code

for shape in output_shape:
if is_nested(shape):
[shapes2.append(s) for s in shape]
else:
shapes2.append(shape)
shapes = output_shape

has no effect on the function output. Perhaps it's some vestige of a previous implementation of the same function that was overlooked for removal? Is there any reason to keep this block of code?

@lukepfister
Copy link
Contributor

@Michael-T-McCann iirc this was your chunk of code

@Michael-T-McCann
Copy link
Contributor

It looks vestigial to me as well, let's remove it.

bwohlberg added a commit that referenced this issue Dec 14, 2021
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

4 participants