Skip to content

Commit

Permalink
python: Upgrade pylint
Browse files Browse the repository at this point in the history
Change-Id: Idd33ba34f523233f8162527788d5b933429042a0
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/128770
Reviewed-by: Ted Pudlik <tpudlik@google.com>
Pigweed-Auto-Submit: Anthony DiGirolamo <tonymd@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
  • Loading branch information
AnthonyDiGirolamo authored and CQ Bot Account committed Mar 3, 2023
1 parent 5068fb5 commit 4129535
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 77 deletions.
38 changes: 19 additions & 19 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
[MASTER] # inclusive-language: ignore

# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-allowlist=mypy

# Add files or directories to the blocklist. They should be base names, not
# paths.
ignore=CVS
Expand All @@ -28,7 +23,7 @@ limit-inference-results=100

# List of plugins (as comma separated values of python module names) to load,
# usually to register additional checkers.
load-plugins=
load-plugins=pylint.extensions.no_self_use

# Pickle collected data for later comparisons.
persistent=yes
Expand Down Expand Up @@ -60,11 +55,23 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable=bad-continuation, # Rely on yapf for formatting
disable=broad-exception-raised,
consider-iterating-dictionary,
consider-using-f-string,
consider-using-generator,
consider-using-in,
consider-using-with,
fixme,
subprocess-run-check,
implicit-str-concat,
raise-missing-from,
redundant-u-string-prefix,
subprocess-run-check,
superfluous-parens,
unnecessary-lambda-assignment,
unspecified-encoding,
use-dict-literal,
use-list-literal,


# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down Expand Up @@ -131,13 +138,6 @@ max-line-length=80
# Maximum number of lines in a module.
max-module-lines=9999

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,
dict-separator

# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
single-line-class-stmt=no
Expand All @@ -161,7 +161,7 @@ allow-global-unused-variables=yes
callbacks=cb_,
_cb

# A regular expression matching the name of placeholder variables (i.e.
# A regular expression matching the name of placeholder variables (i.e.
# expected to not be used). # inclusive-language: ignore
dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_

Expand Down Expand Up @@ -309,7 +309,7 @@ good-names=i,
_

# Include a hint for the correct naming format with invalid-name.
include-naming-hint=no
include-naming-hint=yes

# Naming style matching correct inline iteration names.
inlinevar-naming-style=any
Expand Down Expand Up @@ -511,5 +511,5 @@ preferred-modules=

# Exceptions that will emit a warning when being caught. Defaults to
# "BaseException, Exception".
overgeneral-exceptions=BaseException,
Exception
overgeneral-exceptions=builtins.BaseException,
builtins.Exception
4 changes: 2 additions & 2 deletions pw_build/py/pw_build/project_builder_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def startup_progress(self) -> None:
bottom_toolbar=self.bottom_toolbar,
cancel_callback=self.ctrl_c_interrupt,
)
self.progress_bar.__enter__()
self.progress_bar.__enter__() # pylint: disable=unnecessary-dunder-call

self.create_title_bar_container()
self.progress_bar.app.layout.container.children[ # type: ignore
Expand All @@ -216,7 +216,7 @@ def startup_progress(self) -> None:
def exit_progress(self) -> None:
if not self.progress_bar:
return
self.progress_bar.__exit__()
self.progress_bar.__exit__() # pylint: disable=unnecessary-dunder-call

def clear_progress_scrollback(self) -> None:
if not self.progress_bar:
Expand Down
3 changes: 3 additions & 0 deletions pw_cli/py/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ description = Pigweed swiss-army knife
[options]
packages = find:
zip_safe = False
install_requires =
pyyaml
toml

[options.entry_points]
console_scripts = pw = pw_cli.__main__:main
Expand Down
8 changes: 5 additions & 3 deletions pw_console/py/pw_console/log_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class LogFilter:
field: Optional[str] = None

def pattern(self):
return self.regex.pattern
return self.regex.pattern # pylint: disable=no-member

def matches(self, log: LogLine):
field = log.ansi_stripped_log
Expand All @@ -110,7 +110,7 @@ def matches(self, log: LogLine):
elif self.field == 'time':
field = log.record.asctime

match = self.regex.search(field)
match = self.regex.search(field) # pylint: disable=no-member

if self.invert:
return not match
Expand Down Expand Up @@ -143,7 +143,9 @@ def apply_highlighting(fragments, i):
apply_highlighting(exploded_fragments, i)
else:
# Highlight each non-overlapping search match.
for match in self.regex.finditer(line_text):
for match in self.regex.finditer( # pylint: disable=no-member
line_text
): # pylint: disable=no-member
for fragment_i in range(match.start(), match.end()):
apply_highlighting(exploded_fragments, fragment_i)

Expand Down
8 changes: 5 additions & 3 deletions pw_console/py/pw_console/log_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def update_metadata(self, extra_fields: Optional[Dict] = None):
"""Parse log metadata fields from various sources."""

# 1. Parse any metadata from the message itself.
self.metadata = FormatStringWithMetadata(str(self.record.message))
self.metadata = FormatStringWithMetadata(
str(self.record.message) # pylint: disable=no-member
) # pylint: disable=no-member
self.formatted_log = self.formatted_log.replace(
self.metadata.raw_string, self.metadata.message
)
Expand All @@ -65,9 +67,9 @@ def update_metadata(self, extra_fields: Optional[Dict] = None):
# See:
# https://docs.python.org/3/library/logging.html#logging.debug
if hasattr(self.record, 'extra_metadata_fields') and (
self.record.extra_metadata_fields # type: ignore
self.record.extra_metadata_fields # type: ignore # pylint: disable=no-member
):
fields = self.record.extra_metadata_fields # type: ignore
fields = self.record.extra_metadata_fields # type: ignore # pylint: disable=no-member
for key, value in fields.items():
self.metadata.fields[key] = value

Expand Down
4 changes: 2 additions & 2 deletions pw_console/py/pw_console/progress_bar/progress_bar_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def handle_sigint(_signum, _frame):
# Shut down the ProgressBar prompt_toolkit application
prog_bar = self.instance
if prog_bar is not None and hasattr(prog_bar, '__exit__'):
prog_bar.__exit__()
prog_bar.__exit__() # pylint: disable=unnecessary-dunder-call
raise KeyboardInterrupt

signal.signal(signal.SIGINT, handle_sigint)
Expand All @@ -95,7 +95,7 @@ def startup_progress_bar_impl(self):
)
# Start the ProgressBar prompt_toolkit application in a separate
# thread.
prog_bar.__enter__()
prog_bar.__enter__() # pylint: disable=unnecessary-dunder-call
self.instance = prog_bar
return self.instance

Expand Down
2 changes: 1 addition & 1 deletion pw_console/py/pw_console/pw_ptpython_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def user_code_complete_callback(self, input_text, future):
# Trigger a prompt_toolkit application redraw.
self.repl_pane.application.application.invalidate()

async def _run_system_command(
async def _run_system_command( # pylint: disable=no-self-use
self, text, stdout_proxy, _stdin_proxy
) -> int:
"""Run a shell command and print results to the repl."""
Expand Down
1 change: 1 addition & 0 deletions pw_env_setup/py/pw_env_setup/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ def __call__(self, export=True):
Yields the new environment object.
"""
orig_env = {}
try:
if export:
orig_env = os.environ.copy()
Expand Down
7 changes: 5 additions & 2 deletions pw_env_setup/py/pw_env_setup/virtualenv_setup/constraint.list
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
alabaster==0.7.12
appdirs==1.4.4
astroid==2.6.6
astroid==2.14.2
Babel==2.9.1
backcall==0.2.0
build==0.8.0
Expand All @@ -12,6 +12,7 @@ coloredlogs==15.0.1
coverage==6.3
cryptography==36.0.1
decorator==5.1.1
dill==0.3.6
docutils==0.17.1
breathe==4.34.0
google-api-core==2.7.1
Expand Down Expand Up @@ -41,6 +42,7 @@ parameterized==0.8.1
parso==0.8.3
pep517==0.12.0
pexpect==4.8.0
platformdirs==3.0.0
pickleshare==0.7.5
prompt-toolkit==3.0.36
protobuf==3.20.1
Expand All @@ -51,7 +53,7 @@ pyasn1-modules==0.2.8
pycparser==2.21
pyelftools==0.27
Pygments==2.14.0
pylint==2.9.3
pylint==2.16.2
pyparsing==3.0.6
pyperclip==1.8.2
pyserial==3.5
Expand All @@ -76,6 +78,7 @@ sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
toml==0.10.2
tomli==2.0.0
tomlkit==0.11.6
traitlets==5.1.1
types-docutils==0.17.4
types-futures==3.3.2
Expand Down
32 changes: 16 additions & 16 deletions pw_ide/py/pw_ide/editors.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ def dump(self, data: OrderedDict, *args, **kwargs) -> None:

# Allows constraining to dicts and dict subclasses, while also constraining to
# the *same* dict subclass.
_TDictLike = TypeVar('_TDictLike', bound=Dict)
_DictLike = TypeVar('_DictLike', bound=Dict)


def dict_deep_merge(
src: _TDictLike,
dest: _TDictLike,
ctor: Optional[Callable[[], _TDictLike]] = None,
) -> _TDictLike:
src: _DictLike,
dest: _DictLike,
ctor: Optional[Callable[[], _DictLike]] = None,
) -> _DictLike:
"""Deep merge dict-like `src` into dict-like `dest`.
`dest` is mutated in place and also returned.
Expand Down Expand Up @@ -480,20 +480,20 @@ def all_files(cls) -> Generator['SettingsLevel', None, None]:
# name of that settings file, without the extension.
# TODO(chadnorvell): Would be great to constrain this to enums, but bound=
# doesn't do what we want with Enum or EnumMeta.
_TSettingsType = TypeVar('_TSettingsType')
_SettingsTypeT = TypeVar('_SettingsTypeT')

# Maps each settings type with the callback that generates the default settings
# for that settings type.
EditorSettingsTypesWithDefaults = Dict[_TSettingsType, DefaultSettingsCallback]
EditorSettingsTypesWithDefaults = Dict[_SettingsTypeT, DefaultSettingsCallback]


class EditorSettingsManager(Generic[_TSettingsType]):
class EditorSettingsManager(Generic[_SettingsTypeT]):
"""Manages all settings for a particular editor.
This is where you interact with an editor's settings (actually in a
subclass of this class, not here). Initializing this class sets up access
to one or more settings files for an editor (determined by
``_TSettingsType``, fulfilled by an enum that defines each of an editor's
``_SettingsTypeT``, fulfilled by an enum that defines each of an editor's
settings files), along with the cascading settings levels.
"""

Expand All @@ -509,15 +509,15 @@ class EditorSettingsManager(Generic[_TSettingsType]):
# These must be overridden in child classes.
default_settings_dir: Path = None # type: ignore
file_format: _StructuredFileFormat = _StructuredFileFormat()
types_with_defaults: EditorSettingsTypesWithDefaults[_TSettingsType] = {}
types_with_defaults: EditorSettingsTypesWithDefaults[_SettingsTypeT] = {}

def __init__(
self,
pw_ide_settings: PigweedIdeSettings,
settings_dir: Optional[Path] = None,
file_format: Optional[_StructuredFileFormat] = None,
types_with_defaults: Optional[
EditorSettingsTypesWithDefaults[_TSettingsType]
EditorSettingsTypesWithDefaults[_SettingsTypeT]
] = None,
):
if SettingsLevel.ACTIVE in self.__class__.prefixes:
Expand Down Expand Up @@ -564,7 +564,7 @@ def __init__(
# each settings type. Those settings definitions may be stored in files
# or not.
self._settings_definitions: Dict[
SettingsLevel, Dict[_TSettingsType, EditorSettingsDefinition]
SettingsLevel, Dict[_SettingsTypeT, EditorSettingsDefinition]
] = {}

self._settings_types = tuple(self._types_with_defaults.keys())
Expand Down Expand Up @@ -597,19 +597,19 @@ def __init__(
self._settings_dir, name, self._file_format
)

def default(self, settings_type: _TSettingsType):
def default(self, settings_type: _SettingsTypeT):
"""Default settings for the provided settings type."""
return self._settings_definitions[SettingsLevel.DEFAULT][settings_type]

def project(self, settings_type: _TSettingsType):
def project(self, settings_type: _SettingsTypeT):
"""Project settings for the provided settings type."""
return self._settings_definitions[SettingsLevel.PROJECT][settings_type]

def user(self, settings_type: _TSettingsType):
def user(self, settings_type: _SettingsTypeT):
"""User settings for the provided settings type."""
return self._settings_definitions[SettingsLevel.USER][settings_type]

def active(self, settings_type: _TSettingsType):
def active(self, settings_type: _SettingsTypeT):
"""Active settings for the provided settings type."""
return self._settings_definitions[SettingsLevel.ACTIVE][settings_type]

Expand Down
2 changes: 1 addition & 1 deletion pw_presubmit/py/pw_presubmit/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def test_server(executable: str, output_dir: Path):
yield

finally:
proc.terminate()
proc.terminate() # pylint: disable=used-before-assignment


@filter_paths(
Expand Down
2 changes: 1 addition & 1 deletion pw_presubmit/py/pw_presubmit/presubmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ def _try_call(
_LOG.warning('%s', failure)
return PresubmitResult.FAIL

except Exception as failure: # pylint: disable=broad-except
except Exception as _failure: # pylint: disable=broad-except
_LOG.exception('Presubmit check %s failed!', self.name)
return PresubmitResult.FAIL

Expand Down
10 changes: 5 additions & 5 deletions pw_rpc/py/pw_rpc/callback_client/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ class UseDefault(enum.Enum):
VALUE = 0


CallType = TypeVar(
'CallType',
CallTypeT = TypeVar(
'CallTypeT',
'UnaryCall',
'ServerStreamingCall',
'ClientStreamingCall',
'BidirectionalStreamingCall',
)

OnNextCallback = Callable[[CallType, Any], Any]
OnCompletedCallback = Callable[[CallType, Any], Any]
OnErrorCallback = Callable[[CallType, Any], Any]
OnNextCallback = Callable[[CallTypeT, Any], Any]
OnCompletedCallback = Callable[[CallTypeT, Any], Any]
OnErrorCallback = Callable[[CallTypeT, Any], Any]

OptionalTimeout = Union[UseDefault, float, None]

Expand Down
Loading

0 comments on commit 4129535

Please sign in to comment.