Skip to content

Commit

Permalink
Remove toolz.functoolz.excepts usage (conda#12016)
Browse files Browse the repository at this point in the history
* Remove toolz.functoolz.excepts usage

* Add news
  • Loading branch information
kenodegard authored Oct 26, 2022
1 parent c920162 commit 2168064
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 27 deletions.
39 changes: 19 additions & 20 deletions conda/common/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
try:
from tlz.itertoolz import concat, concatv, unique
from tlz.dicttoolz import merge, merge_with
from tlz.functoolz import excepts
except ImportError:
from conda._vendor.toolz.itertoolz import concat, concatv, unique
from conda._vendor.toolz.dicttoolz import merge, merge_with
from conda._vendor.toolz import excepts

from .compat import isiterable, odict, primitive_types
from .constants import NULL
Expand Down Expand Up @@ -341,16 +339,18 @@ def _get_yaml_key_comment(commented_dict, key):
except (AttributeError, KeyError):
return None

@staticmethod
def _get_yaml_list_comments(value):
items = value.ca.items
raw_comment_lines = tuple(excepts((AttributeError, IndexError, KeyError, TypeError),
lambda q: YamlRawParameter._get_yaml_list_comment_item(
items[q]),
lambda _: None # default value on exception
)(q)
for q in range(len(value)))
return raw_comment_lines
@classmethod
def _get_yaml_list_comments(cls, value):
# value is a ruamel.yaml CommentedSeq, len(value) is the number of lines in the sequence,
# value.ca is the comment object for the sequence and the comments themselves are stored as
# a sparse dict
list_comments = []
for i in range(len(value)):
try:
list_comments.append(cls._get_yaml_list_comment_item(value.ca.items[i]))
except (AttributeError, IndexError, KeyError, TypeError):
list_comments.append(None)
return tuple(list_comments)

@staticmethod
def _get_yaml_list_comment_item(item):
Expand All @@ -363,14 +363,13 @@ def _get_yaml_list_comment_item(item):

@staticmethod
def _get_yaml_map_comments(value):
return {
key: excepts(
(AttributeError, KeyError),
lambda k: value.ca.items[k][2].value.strip() or None,
lambda _: None, # default value on exception
)(key)
for key in value
}
map_comments = {}
for key in value:
try:
map_comments[key] = value.ca.items[key][2].value.strip() or None
except (AttributeError, KeyError):
map_comments[key] = None
return map_comments

@classmethod
def make_raw_parameters(cls, source, from_map):
Expand Down
14 changes: 7 additions & 7 deletions conda/models/version.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
from __future__ import annotations

from logging import getLogger
import operator as op
import re
from itertools import zip_longest

try:
from tlz.functoolz import excepts
except ImportError:
from conda._vendor.toolz.functoolz import excepts

from ..exceptions import InvalidVersionSpec

log = getLogger(__name__)
Expand Down Expand Up @@ -663,8 +660,11 @@ def union(self, other):
return '|'.join(options)

@property
def exact_value(self):
return excepts(ValueError, int(self.raw_value))
def exact_value(self) -> int | None:
try:
return int(self.raw_value)
except ValueError:
return None

def __str__(self):
return str(self.spec)
Expand Down
19 changes: 19 additions & 0 deletions news/12016-stop-using-toolz.functoolz.excepts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Stop using `toolz.functoolz.excepts`. (#12016)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>

0 comments on commit 2168064

Please sign in to comment.