Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set return type to None for functions without returns #581

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions pylsp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)


def add_arguments(parser):
def add_arguments(parser) -> None:
parser.description = "Python Language Server"

parser.add_argument(
Expand Down Expand Up @@ -67,7 +67,7 @@ def add_arguments(parser):
)


def main():
def main() -> None:
parser = argparse.ArgumentParser()
add_arguments(parser)
args = parser.parse_args()
Expand All @@ -94,7 +94,7 @@ def _binary_stdio():
return stdin, stdout


def _configure_logger(verbose=0, log_config=None, log_file=None):
def _configure_logger(verbose=0, log_config=None, log_file=None) -> None:
root_logger = logging.root

if log_config:
Expand Down
6 changes: 3 additions & 3 deletions pylsp/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _hookexec(


class Config:
def __init__(self, root_uri, init_opts, process_id, capabilities):
def __init__(self, root_uri, init_opts, process_id, capabilities) -> None:
self._root_path = uris.to_fs_path(root_uri)
self._root_uri = root_uri
self._init_opts = init_opts
Expand Down Expand Up @@ -185,14 +185,14 @@ def plugin_settings(self, plugin, document_path=None):
.get(plugin, {})
)

def update(self, settings):
def update(self, settings) -> None:
"""Recursively merge the given settings into the current settings."""
self.settings.cache_clear()
self._settings = settings
log.info("Updated settings to %s", self._settings)
self._update_disabled_plugins()

def _update_disabled_plugins(self):
def _update_disabled_plugins(self) -> None:
# All plugins default to enabled
self._disabled_plugins = [
plugin
Expand Down
6 changes: 3 additions & 3 deletions pylsp/config/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
class ConfigSource:
"""Base class for implementing a config source."""

def __init__(self, root_path):
def __init__(self, root_path) -> None:
self.root_path = root_path
self.is_windows = sys.platform == "win32"
self.xdg_home = os.environ.get(
"XDG_CONFIG_HOME", os.path.expanduser("~/.config")
)

def user_config(self):
def user_config(self) -> None:
"""Return user-level (i.e. home directory) configuration."""
raise NotImplementedError()

def project_config(self, document_path):
def project_config(self, document_path) -> None:
"""Return project-level (i.e. workspace directory) configuration."""
raise NotImplementedError()

Expand Down
50 changes: 26 additions & 24 deletions pylsp/hookspecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def pylsp_code_actions(config, workspace, document, range, context):


@hookspec
def pylsp_code_lens(config, workspace, document):
def pylsp_code_lens(config, workspace, document) -> None:
pass


@hookspec
def pylsp_commands(config, workspace):
def pylsp_commands(config, workspace) -> None:
"""The list of command strings supported by the server.

Returns:
Expand All @@ -24,110 +24,112 @@ def pylsp_commands(config, workspace):


@hookspec
def pylsp_completions(config, workspace, document, position, ignored_names):
def pylsp_completions(config, workspace, document, position, ignored_names) -> None:
pass


@hookspec(firstresult=True)
def pylsp_completion_item_resolve(config, workspace, document, completion_item):
def pylsp_completion_item_resolve(config, workspace, document, completion_item) -> None:
pass


@hookspec
def pylsp_definitions(config, workspace, document, position):
def pylsp_definitions(config, workspace, document, position) -> None:
pass


@hookspec
def pylsp_dispatchers(config, workspace):
def pylsp_dispatchers(config, workspace) -> None:
pass


@hookspec
def pylsp_document_did_open(config, workspace, document):
def pylsp_document_did_open(config, workspace, document) -> None:
pass


@hookspec
def pylsp_document_did_save(config, workspace, document):
def pylsp_document_did_save(config, workspace, document) -> None:
pass


@hookspec
def pylsp_document_highlight(config, workspace, document, position):
def pylsp_document_highlight(config, workspace, document, position) -> None:
pass


@hookspec
def pylsp_document_symbols(config, workspace, document):
def pylsp_document_symbols(config, workspace, document) -> None:
pass


@hookspec(firstresult=True)
def pylsp_execute_command(config, workspace, command, arguments):
def pylsp_execute_command(config, workspace, command, arguments) -> None:
pass


@hookspec
def pylsp_experimental_capabilities(config, workspace):
def pylsp_experimental_capabilities(config, workspace) -> None:
pass


@hookspec
def pylsp_folding_range(config, workspace, document):
def pylsp_folding_range(config, workspace, document) -> None:
pass


@hookspec(firstresult=True)
def pylsp_format_document(config, workspace, document, options):
def pylsp_format_document(config, workspace, document, options) -> None:
pass


@hookspec(firstresult=True)
def pylsp_format_range(config, workspace, document, range, options):
def pylsp_format_range(config, workspace, document, range, options) -> None:
pass


@hookspec(firstresult=True)
def pylsp_hover(config, workspace, document, position):
def pylsp_hover(config, workspace, document, position) -> None:
pass


@hookspec
def pylsp_initialize(config, workspace):
def pylsp_initialize(config, workspace) -> None:
pass


@hookspec
def pylsp_initialized():
def pylsp_initialized() -> None:
pass


@hookspec
def pylsp_lint(config, workspace, document, is_saved):
def pylsp_lint(config, workspace, document, is_saved) -> None:
pass


@hookspec
def pylsp_references(config, workspace, document, position, exclude_declaration):
def pylsp_references(
config, workspace, document, position, exclude_declaration
) -> None:
pass


@hookspec(firstresult=True)
def pylsp_rename(config, workspace, document, position, new_name):
def pylsp_rename(config, workspace, document, position, new_name) -> None:
pass


@hookspec
def pylsp_settings(config):
def pylsp_settings(config) -> None:
pass


@hookspec(firstresult=True)
def pylsp_signature_help(config, workspace, document, position):
def pylsp_signature_help(config, workspace, document, position) -> None:
pass


@hookspec
def pylsp_workspace_configuration_changed(config, workspace):
def pylsp_workspace_configuration_changed(config, workspace) -> None:
pass
4 changes: 2 additions & 2 deletions pylsp/plugins/_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# ---- Base class
# -----------------------------------------------------------------------------
class Resolver:
def __init__(self, callback, resolve_on_error, time_to_live=60 * 30):
def __init__(self, callback, resolve_on_error, time_to_live=60 * 30) -> None:
self.callback = callback
self.resolve_on_error = resolve_on_error
self._cache = {}
Expand All @@ -33,7 +33,7 @@ def cached_modules(self):
def cached_modules(self, new_value):
self._cached_modules = set(new_value)

def clear_outdated(self):
def clear_outdated(self) -> None:
now = self.time_key()
to_clear = [timestamp for timestamp in self._cache_ttl if timestamp < now]
for time_key in to_clear:
Expand Down
6 changes: 3 additions & 3 deletions pylsp/plugins/_rope_task_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PylspJobSet(BaseJobSet):
_report_iter: ContextManager
job_name: str = ""

def __init__(self, count: Optional[int], report_iter: ContextManager):
def __init__(self, count: Optional[int], report_iter: ContextManager) -> None:
if count is not None:
self.count = count
self._reporter = report_iter.__enter__()
Expand Down Expand Up @@ -57,7 +57,7 @@ def increment(self) -> None:
self._report()

@throttle(0.5)
def _report(self):
def _report(self) -> None:
percent = int(self.get_percent_done())
message = f"{self.job_name} {self.done}/{self.count}"
log.debug(f"Reporting {message} {percent}%")
Expand All @@ -72,7 +72,7 @@ class PylspTaskHandle(BaseTaskHandle):
workspace: Workspace
_report: Callable[[str, str], None]

def __init__(self, workspace: Workspace):
def __init__(self, workspace: Workspace) -> None:
self.workspace = workspace
self.job_sets = []
self.observers = []
Expand Down
2 changes: 1 addition & 1 deletion pylsp/plugins/preload_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def pylsp_settings():


@hookimpl
def pylsp_initialize(config):
def pylsp_initialize(config) -> None:
for mod_name in config.plugin_settings("preload").get("modules", []):
try:
__import__(mod_name)
Expand Down
2 changes: 1 addition & 1 deletion pylsp/plugins/pycodestyle_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def pylsp_lint(workspace, document):


class PyCodeStyleDiagnosticReport(pycodestyle.BaseReport):
def __init__(self, options):
def __init__(self, options) -> None:
self.diagnostics = []
super().__init__(options=options)

Expand Down
2 changes: 1 addition & 1 deletion pylsp/plugins/pydocstyle_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _parse_diagnostic(document, error):


@contextlib.contextmanager
def _patch_sys_argv(arguments):
def _patch_sys_argv(arguments) -> None:
old_args = sys.argv

# Preserve argv[0] since it's the executable
Expand Down
8 changes: 4 additions & 4 deletions pylsp/plugins/pyflakes_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def pylsp_lint(workspace, document):


class PyflakesDiagnosticReport:
def __init__(self, lines):
def __init__(self, lines) -> None:
self.lines = lines
self.diagnostics = []

def unexpectedError(self, _filename, msg): # pragma: no cover
def unexpectedError(self, _filename, msg) -> None: # pragma: no cover
err_range = {
"start": {"line": 0, "character": 0},
"end": {"line": 0, "character": 0},
Expand All @@ -50,7 +50,7 @@ def unexpectedError(self, _filename, msg): # pragma: no cover
}
)

def syntaxError(self, _filename, msg, lineno, offset, text):
def syntaxError(self, _filename, msg, lineno, offset, text) -> None:
# We've seen that lineno and offset can sometimes be None
lineno = lineno or 1
offset = offset or 0
Expand All @@ -71,7 +71,7 @@ def syntaxError(self, _filename, msg, lineno, offset, text):
}
)

def flake(self, message):
def flake(self, message) -> None:
"""Get message like <filename>:<lineno>: <msg>"""
err_range = {
"start": {"line": message.lineno - 1, "character": message.col},
Expand Down
14 changes: 8 additions & 6 deletions pylsp/plugins/rope_autoimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class AutoimportCache:
"""Handles the cache creation."""

def __init__(self):
def __init__(self) -> None:
self.thread = None

def reload_cache(
Expand Down Expand Up @@ -66,7 +66,7 @@ def _reload_cache(
workspace: Workspace,
autoimport: AutoImport,
resources: Optional[List[Resource]] = None,
):
) -> None:
task_handle = PylspTaskHandle(workspace)
autoimport.generate_cache(task_handle=task_handle, resources=resources)
autoimport.generate_modules_cache(task_handle=task_handle)
Expand Down Expand Up @@ -365,7 +365,7 @@ def pylsp_code_actions(


@hookimpl
def pylsp_initialize(config: Config, workspace: Workspace):
def pylsp_initialize(config: Config, workspace: Workspace) -> None:
"""Initialize AutoImport.

Generates the cache for local and global items.
Expand All @@ -374,7 +374,7 @@ def pylsp_initialize(config: Config, workspace: Workspace):


@hookimpl
def pylsp_document_did_open(config: Config, workspace: Workspace):
def pylsp_document_did_open(config: Config, workspace: Workspace) -> None:
"""Initialize AutoImport.

Generates the cache for local and global items.
Expand All @@ -383,13 +383,15 @@ def pylsp_document_did_open(config: Config, workspace: Workspace):


@hookimpl
def pylsp_document_did_save(config: Config, workspace: Workspace, document: Document):
def pylsp_document_did_save(
config: Config, workspace: Workspace, document: Document
) -> None:
"""Update the names associated with this document."""
cache.reload_cache(config, workspace, [document])


@hookimpl
def pylsp_workspace_configuration_changed(config: Config, workspace: Workspace):
def pylsp_workspace_configuration_changed(config: Config, workspace: Workspace) -> None:
"""
Initialize autoimport if it has been enabled through a
workspace/didChangeConfiguration message from the frontend.
Expand Down
Loading