Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Sep 24, 2024
1 parent 83cc31c commit b370363
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 54 deletions.
56 changes: 16 additions & 40 deletions pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,26 +201,6 @@ def _similar_names(
return sorted(picked)


def _missing_member_hint(
owner: SuccessfulInferenceResult,
attrname: str | None,
distance_threshold: int,
max_choices: int,
) -> str:
names = _similar_names(owner, attrname, distance_threshold, max_choices)
if not names:
# No similar name.
return ""

names = [repr(name) for name in names]
if len(names) == 1:
names_hint = ", ".join(names)
else:
names_hint = f"one of {', '.join(names[:-1])} or {names[-1]}"

return f"; maybe {names_hint}?"


MSGS: dict[str, MessageDefinitionTuple] = {
"E1101": (
"%s %r has no %r member%s",
Expand Down Expand Up @@ -988,10 +968,6 @@ def open(self) -> None:
self._py310_plus = py_version >= (3, 10)
self._mixin_class_rgx = self.linter.config.mixin_class_rgx

@cached_property
def _suggestion_mode(self) -> bool:
return self.linter.config.suggestion_mode # type: ignore[no-any-return]

@cached_property
def _compiled_generated_members(self) -> tuple[Pattern[str], ...]:
# do this lazily since config not fully initialized in __init__
Expand Down Expand Up @@ -1202,24 +1178,24 @@ def _get_nomember_msgid_hint(
node: nodes.Attribute | nodes.AssignAttr | nodes.DelAttr,
owner: SuccessfulInferenceResult,
) -> tuple[Literal["c-extension-no-member", "no-member"], str]:
suggestions_are_possible = self._suggestion_mode and isinstance(
owner, nodes.Module
if isinstance(owner, nodes.Module) and _is_c_extension(owner):
return "c-extension-no-member", ""
if not self.linter.config.missing_member_hint:
return "no-member", ""
names = _similar_names(
owner,
node.attrname,
self.linter.config.missing_member_hint_distance,
self.linter.config.missing_member_max_choices,
)
if suggestions_are_possible and _is_c_extension(owner):
msg = "c-extension-no-member"
hint = ""
if not names:
return "no-member", ""
names = [repr(name) for name in names]
if len(names) == 1:
names_hint = ", ".join(names)
else:
msg = "no-member"
if self.linter.config.missing_member_hint:
hint = _missing_member_hint(
owner,
node.attrname,
self.linter.config.missing_member_hint_distance,
self.linter.config.missing_member_max_choices,
)
else:
hint = ""
return msg, hint # type: ignore[return-value]
names_hint = f"one of {', '.join(names[:-1])} or {names[-1]}"
return "no-member", f"; maybe {names_hint}?"

@only_required_for_messages(
"assignment-from-no-return",
Expand Down
13 changes: 0 additions & 13 deletions pylint/lint/base_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,19 +306,6 @@ def _make_linter_options(linter: PyLinter) -> Options:
),
},
),
(
"suggestion-mode",
{
"type": "yn",
"metavar": "<y or n>",
"default": True,
"help": (
"When enabled, pylint would attempt to guess common "
"misconfiguration and emit user-friendly hints instead "
"of false-positive error messages."
),
},
),
(
"exit-zero",
{
Expand Down
1 change: 0 additions & 1 deletion pylint/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

# These are types used to overload get_global_option() and refer to the options type
GLOBAL_OPTION_BOOL = Literal[
"suggestion-mode",
"analyse-fallback-blocks",
"allow-global-unused-variables",
"prefer-stubs",
Expand Down

0 comments on commit b370363

Please sign in to comment.