Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions refex/fix/fixers/idiom_fixers.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def f(x):

_NEGATION_CATEGORY = 'pylint.g-comparison-negation'
_UNNECESSARY_COMPREHENSION_CATEGORY = 'idioms.uncessary-comprehension'
_OS_PATH_CATEGORY = 'idioms.os-path'

_Try = getattr(ast_matchers, 'Try', getattr(ast_matchers, 'TryExcept', None)) # type alias; pylint: disable=invalid-name

Expand Down Expand Up @@ -396,6 +397,22 @@ def _in_exception_handler(identifier, on_conflict):
'{$a for $a in $b}',
'set($b)',
category=_UNNECESSARY_COMPREHENSION_CATEGORY),
idiom_fixer(
'$a = os.path.split($b)[0]',
'$a = os.path.dirname($b)',
category=_OS_PATH_CATEGORY),
idiom_fixer(
'$a = os.path.split($b)[1]',
'$a = os.path.basename($b)',
category=_OS_PATH_CATEGORY),
idiom_fixer(
'$a, _ = os.path.split($b)',
'$a = os.path.dirname($b)',
category=_OS_PATH_CATEGORY),
idiom_fixer(
'_ , $a = os.path.split($b)',
'$a = os.path.basename($b)',
category=_OS_PATH_CATEGORY),
] + list(_MUTABLE_CONSTANT_FIXERS) + list(_LOGGING_FIXERS)

# TODO(b/152805392): + _NONE_RETURNS_FIXERS