-
Notifications
You must be signed in to change notification settings - Fork 1.9k
remove toolz.concatv #11769
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
remove toolz.concatv #11769
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that almost all of the concatv
/chain
use cases are immediately evaluated/expanded into some tuple, list, or other frozen data type. Since that's the case can we just use arg unpacking?
@@ -122,7 +118,7 @@ def get_scripts_export_unset_vars(self, **kwargs): | |||
return script_export_vars or '', script_unset_vars or '' | |||
|
|||
def _finalize(self, commands, ext): | |||
commands = concatv(commands, ('',)) # add terminating newline | |||
commands = chain(commands, ('',)) # add terminating newline |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, no benefit in leaving this as a generator and the NotImplementedError
seems very unnecessary:
def _finalize(self, commands, ext):
script = self.command_join.join((*commands, ")) # add terminating newline
if ext:
# the default mode is 'w+b', and universal new lines don't work in that mode
# command_join should account for that
with Utf8NamedTemporaryFile('w+', suffix=ext, delete=False) as tf:
tf.write(script)
return tf.name
else:
return script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where's the NotImplementedError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 135 of conda/activate.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess ext could be the empty string sometimes? However it's not related to concatv
in any way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather leave it as chain()
because I'm not familiar with arg unpacking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kenodegard do you need this PR to use *arg unpacking whenever it is possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, agreed that NotImplementedError
isn't useful here, it's kind of misused for this case, since that's supposed to be an exception for base classes that require certain methods to be overridden in subclasses.
8120164
to
b77f824
Compare
|
||
import itertools | ||
|
||
concat = itertools.chain.from_iterable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the indirect module from conda.tlz import x
to place these two lines in one place (the indirection module), instead of everywhere that particular toolz is uzed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add this to conda.common
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I'm a little on the fence if we'll basically never allow generators to be used here in the future?
If I'm not mistaken this PR replaces concat / concatv (which literally contain only calls to itertools.chain or itertools.chain.from_iterable) with direct calls to chain or chain.from_iterable |
Obsolete |
Description
itertools.chain()
is used since conda's arguments toconcatv
are never generatorsReplace verbatim copy of toolz.unique with import.
See also #11698