Skip to content

Commit dca6c8f

Browse files
committed
fixing R rules
1 parent 27190ff commit dca6c8f

14 files changed

+56
-66
lines changed

.github/scripts/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ python setup.py develop
2424
python -m pytest # Run the tests without IPython.
2525
pip install ipython
2626
python -m pytest # Now run the tests with IPython.
27-
pre-commit run --all-files
27+
pre-commit run --all-files --show-diff-on-failure --
2828
if [[ ${PYTHON_VERSION} == 3.7 ]]; then
2929
# Run type-checking.
3030
pip install pytype;

fire/completion.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ def _BashScript(name, commands, default_options=None):
151151
def _GetOptsAssignmentTemplate(command):
152152
if command == name:
153153
return opts_assignment_main_command_template
154-
else:
155-
return opts_assignment_subcommand_template
154+
return opts_assignment_subcommand_template
156155

157156
lines = []
158157
commands_set = set()
@@ -281,7 +280,7 @@ def _FishScript(name, commands, default_options=None):
281280
)
282281

283282

284-
def MemberVisible(component, name, member, class_attrs=None, verbose=False):
283+
def MemberVisible(component, name, member, class_attrs=None, verbose=False): # noqa: C901
285284
"""Returns whether a member should be included in auto-completion or help.
286285
287286
Determines whether a member of an object with the specified name should be

fire/console/console_attr.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def _GetConsoleEncoding(self):
314314
console_encoding = console_encoding.lower()
315315
if 'utf-8' in console_encoding:
316316
return 'utf8'
317-
elif 'cp437' in console_encoding:
317+
if 'cp437' in console_encoding:
318318
return 'cp437'
319319
return None
320320

@@ -700,15 +700,14 @@ def GetCharacterDisplayWidth(char):
700700
if unicodedata.combining(char) != 0:
701701
# Modifies the previous character and does not move the cursor.
702702
return 0
703-
elif unicodedata.category(char) == 'Cf':
703+
if unicodedata.category(char) == 'Cf':
704704
# Unprintable formatting char.
705705
return 0
706-
elif unicodedata.east_asian_width(char) in 'FW':
706+
if unicodedata.east_asian_width(char) in 'FW':
707707
# Fullwidth or Wide chars take 2 character positions.
708708
return 2
709-
else:
710-
# Don't use this function on control chars.
711-
return 1
709+
# Don't use this function on control chars.
710+
return 1
712711

713712

714713
def SafeText(data, encoding=None, escape=True):

fire/console/console_pager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def _Help(self):
166166
self._attr.GetRawKey()
167167
self._Write('\n')
168168

169-
def Run(self):
169+
def Run(self): # noqa: C901
170170
"""Run the pager."""
171171
# No paging if the contents are small enough.
172172
if len(self._lines) <= self._height:
@@ -215,7 +215,7 @@ def Run(self):
215215
):
216216
# Quit.
217217
return
218-
elif c in ('/', '?'):
218+
if c in ('/', '?'):
219219
c = self._GetSearchCommand(c)
220220
elif c.isdigit():
221221
# Collect digits for operation count.

fire/console/files.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ def _FindExecutableOnPath(executable, path, pathext):
6666
def _PlatformExecutableExtensions(platform):
6767
if platform == platforms.OperatingSystem.WINDOWS:
6868
return ('.exe', '.cmd', '.bat', '.com', '.ps1')
69-
else:
70-
return ('', '.sh')
69+
return ('', '.sh')
7170

7271

7372
def FindExecutableOnPath(executable, path=None, pathext=None,

fire/console/platforms.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ def Current():
147147
"""
148148
if os.name == 'nt':
149149
return OperatingSystem.WINDOWS
150-
elif 'linux' in sys.platform:
150+
if 'linux' in sys.platform:
151151
return OperatingSystem.LINUX
152-
elif 'darwin' in sys.platform:
152+
if 'darwin' in sys.platform:
153153
return OperatingSystem.MACOSX
154-
elif 'cygwin' in sys.platform:
154+
if 'cygwin' in sys.platform:
155155
return OperatingSystem.CYGWIN
156-
elif 'msys' in sys.platform:
156+
if 'msys' in sys.platform:
157157
return OperatingSystem.MSYS
158158
return None
159159

@@ -323,12 +323,12 @@ def UserAgentFragment(self):
323323
# '#1 SMP Tue May 21 02:35:06 PDT 2013', 'x86_64', 'x86_64')
324324
return '({name} {version})'.format(
325325
name=self.operating_system.name, version=platform.release())
326-
elif self.operating_system == OperatingSystem.WINDOWS:
326+
if self.operating_system == OperatingSystem.WINDOWS:
327327
# ('Windows', '<hostname goes here>', '7', '6.1.7601', 'AMD64',
328328
# 'Intel64 Family 6 Model 45 Stepping 7, GenuineIntel')
329329
return '({name} NT {version})'.format(
330330
name=self.operating_system.name, version=platform.version())
331-
elif self.operating_system == OperatingSystem.MACOSX:
331+
if self.operating_system == OperatingSystem.MACOSX:
332332
# ('Darwin', '<hostname goes here>', '12.4.0',
333333
# 'Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013;
334334
# root:xnu-2050.24.15~1/RELEASE_X86_64', 'x86_64', 'i386')
@@ -337,8 +337,7 @@ def UserAgentFragment(self):
337337
if self.architecture == Architecture.ppc else 'Intel')
338338
return format_string.format(
339339
name=arch_string, version=platform.release())
340-
else:
341-
return '()'
340+
return '()'
342341

343342
def AsyncPopenArgs(self):
344343
"""Returns the args for spawning an async process using Popen on this OS.
@@ -413,10 +412,9 @@ def SupportedVersionMessage(self, allow_py3):
413412
PythonVersion.MIN_SUPPORTED_PY2_VERSION[1],
414413
PythonVersion.MIN_SUPPORTED_PY3_VERSION[0],
415414
PythonVersion.MIN_SUPPORTED_PY3_VERSION[1])
416-
else:
417-
return 'Please use Python version {0}.{1}.x.'.format(
418-
PythonVersion.MIN_SUPPORTED_PY2_VERSION[0],
419-
PythonVersion.MIN_SUPPORTED_PY2_VERSION[1])
415+
return 'Please use Python version {0}.{1}.x.'.format(
416+
PythonVersion.MIN_SUPPORTED_PY2_VERSION[0],
417+
PythonVersion.MIN_SUPPORTED_PY2_VERSION[1])
420418

421419
def IsCompatible(self, allow_py3=False, raise_exception=False):
422420
"""Ensure that the Python version we are using is compatible.

fire/core.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ def Fire(component=None, command=None, name=None, serialize=None):
160160
# The command succeeded normally; print the result.
161161
_PrintResult(
162162
component_trace, verbose=component_trace.verbose, serialize=serialize)
163-
result = component_trace.GetResult()
164-
return result
163+
return component_trace.GetResult()
165164

166165

167166
def Display(lines, out):
@@ -236,7 +235,7 @@ def _IsHelpShortcut(component_trace, remaining_args):
236235
return show_help
237236

238237

239-
def _PrintResult(component_trace, verbose=False, serialize=None):
238+
def _PrintResult(component_trace, verbose=False, serialize=None): # noqa: C901
240239
"""Prints the result of the Fire call to stdout in a human readable way."""
241240
# TODO(dbieber): Design human readable deserializable serialization method
242241
# and move serialization to its own module.
@@ -358,7 +357,7 @@ def _OneLineResult(result):
358357
return str(result).replace('\n', ' ')
359358

360359

361-
def _Fire(component, args, parsed_flag_args, context, name=None):
360+
def _Fire(component, args, parsed_flag_args, context, name=None): # noqa: C901
362361
"""Execute a Fire command on a target component using the args supplied.
363362
364363
Arguments that come after a final isolated '--' are treated as Flags, eg for
@@ -813,7 +812,7 @@ def _ParseArgs(fn_args, fn_defaults, num_required_args, kwargs,
813812
return parsed_args, kwargs, remaining_args, capacity
814813

815814

816-
def _ParseKeywordArgs(args, fn_spec):
815+
def _ParseKeywordArgs(args, fn_spec): # noqa: C901
817816
"""Parses the supplied arguments for keyword arguments.
818817
819818
Given a list of arguments, finds occurrences of --name value, and uses 'name'

fire/decorators.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ def GetMetadata(fn) -> Dict[str, Any]:
9898
metadata = getattr(fn, FIRE_METADATA, default)
9999
if ACCEPTS_POSITIONAL_ARGS in metadata:
100100
return metadata
101-
else:
102-
return default
101+
return default
103102
except: # noqa: E722
104103
return default
105104

fire/docstrings.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ def _as_arg_name_and_type(text):
338338
type_token = ' '.join(tokens[1:])
339339
type_token = type_token.lstrip('{([').rstrip('])}')
340340
return tokens[0], type_token
341-
else:
342-
return None
341+
return None
343342

344343

345344
def _as_arg_names(names_str):
@@ -408,7 +407,7 @@ def _consume_google_args_line(line_info, state):
408407
state.current_arg.description.lines.append(split_line[0])
409408

410409

411-
def _consume_line(line_info, state):
410+
def _consume_line(line_info, state): # noqa: C901
412411
"""Consumes one line of text, updating the state accordingly.
413412
414413
When _consume_line is called, part of the line may already have been processed
@@ -689,17 +688,15 @@ def _get_directive(line_info):
689688
"""
690689
if line_info.stripped.startswith(':'):
691690
return line_info.stripped.split(':', 2)[1]
692-
else:
693-
return None
691+
return None
694692

695693

696694
def _get_after_directive(line_info):
697695
"""Gets the remainder of the line, after a directive."""
698696
sections = line_info.stripped.split(':', 2)
699697
if len(sections) > 2:
700698
return sections[-1]
701-
else:
702-
return ''
699+
return ''
703700

704701

705702
def _rst_section(line_info):
@@ -717,8 +714,7 @@ def _rst_section(line_info):
717714
if directive:
718715
possible_title = directive.split()[0]
719716
return _section_from_possible_title(possible_title)
720-
else:
721-
return None
717+
return None
722718

723719

724720
def _line_is_hyphens(line):
@@ -744,8 +740,7 @@ def _numpy_section(line_info):
744740
if next_line_is_hyphens:
745741
possible_title = line_info.remaining
746742
return _section_from_possible_title(possible_title)
747-
else:
748-
return None
743+
return None
749744

750745

751746
def _line_is_numpy_parameter_type(line_info):
@@ -769,6 +764,5 @@ def _line_is_numpy_parameter_type(line_info):
769764
if ':' in line_info.previous.line and current_indent > previous_indent:
770765
# The parameter type was the previous line; this is the description.
771766
return False
772-
else:
773-
return True
767+
return True
774768
return False

fire/helptext.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ def _DescriptionSection(component, info):
160160
text = description or summary or None
161161
if text:
162162
return ('DESCRIPTION', text)
163-
else:
164-
return None
163+
return None
165164

166165

167166
def _CreateKeywordOnlyFlagItem(flag, docstring_info, spec, short_arg):
@@ -185,7 +184,7 @@ def _GetShortFlags(flags):
185184
return [v for v in short_flags if short_flag_counts[v] == 1]
186185

187186

188-
def _ArgsAndFlagsSections(info, spec, metadata):
187+
def _ArgsAndFlagsSections(info, spec, metadata): # noqa: C901
189188
"""The "Args and Flags" sections of the help string."""
190189
args_with_no_defaults = spec.args[:len(spec.args) - len(spec.defaults)]
191190
args_with_defaults = spec.args[len(spec.args) - len(spec.defaults):]

fire/inspectutils.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class with an __init__ method.
8585
return fn, skip_arg
8686

8787

88-
def Py3GetFullArgSpec(fn):
88+
def Py3GetFullArgSpec(fn): # noqa: C901
8989
"""A alternative to the builtin getfullargspec.
9090
9191
The builtin inspect.getfullargspec uses:
@@ -326,8 +326,7 @@ def IsNamedTuple(component):
326326
if not isinstance(component, tuple):
327327
return False
328328

329-
has_fields = bool(getattr(component, '_fields', None))
330-
return has_fields
329+
return bool(getattr(component, '_fields', None)) # whether it has files
331330

332331

333332
def GetClassAttrsDict(component):

fire/interact_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
try:
24-
import IPython # noqa: F401
24+
import IPython
2525
INTERACT_METHOD = 'IPython.start_ipython'
2626
except ImportError:
2727
INTERACT_METHOD = 'code.InteractiveConsole'

fire/trace.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,14 @@ def ErrorAsStr(self):
294294
def __str__(self):
295295
if self.HasError():
296296
return self.ErrorAsStr()
297-
else:
298-
# Format is: {action} "{target}" ({filename}:{lineno})
299-
string = self._action
300-
if self._target is not None:
301-
string += f' "{self._target}"'
302-
if self._filename is not None:
303-
path = self._filename
304-
if self._lineno is not None:
305-
path += f':{self._lineno}'
306-
307-
string += f' ({path})'
308-
return string
297+
# Format is: {action} "{target}" ({filename}:{lineno})
298+
string = self._action
299+
if self._target is not None:
300+
string += f' "{self._target}"'
301+
if self._filename is not None:
302+
path = self._filename
303+
if self._lineno is not None:
304+
path += f':{self._lineno}'
305+
306+
string += f' ({path})'
307+
return string

pyproject.toml

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ output = ".pytype"
1616
line-length = 80
1717

1818
# Enable specific rule categories
19-
lint.select = ["E", "F", "W", "RUF100"]
19+
lint.select = [
20+
"E", # Errors
21+
"W", # Warnings
22+
"C", # Conventions
23+
"R", # Refactors
24+
"RUF100", # Remove unused noqas
25+
]
2026

2127
# Exclude specific files and directories
2228
lint.exclude = ["build", "dist", ".venv"]

0 commit comments

Comments
 (0)