reportUnusedFunction.md
April 8, 2026 · View on GitHub
Overview
reportUnusedFunction is a Pylance and Pyright diagnostic that warns when a function is defined but never used in your code. Removing unused functions helps keep your codebase clean and maintainable.
Representative Issues
- #2840: Enhance the static analysis capabilities of Pylance to include warnings for unused function parameters, similar to how it handles other unreferenced elements in the code.
- #3102: Ensure that default argument types in functions match the annotated parameter types to avoid runtime errors and type checking issues.
- #4163: Ensure consistency in the use of type stubs between Pyright's CLI and Pylance settings, especially with
useLibraryCodeForTypes. - #495: Utilize the
excludeproperty in Pyright's config file to prevent analysis of unwanted folders, ensuring smoother configuration and reduced diagnostics clutter. - #5200: Provide a configuration setting to allow users to customize diagnostic rule severities based on the type checking mode, improving the granularity of error reporting.
- #6300: When configuring file exclusions in a Python project, it's crucial to accurately exclude unnecessary folders like .venv to improve performance.
- #1462: Always verify that configuration settings are respected by CLI tools in applications, especially when dealing with library code for types.
- #2307: Ensure that configuration settings for unused variables are correctly applied and respected by the language server.
- #5411: Always use the explicit
AsyncGeneratortype annotation for async generator functions to avoid inconsistencies with inferred types. - #5412: When using
type(self)as a constructor in a generic class, ensure to dynamically generate the correct specialized type for subclasses. - #6747: When using private functions within a module, ensure that the
reportUnusedFunctioncheck is disabled to avoid false positives in static analysis tools like Pyright.
Examples
Error:
def _unused_helper(x: int) -> int: # Defined but never called
return x * 2
def main():
print("hello")
Fix — remove the unused function or use it:
def main():
print("hello")
Or, if the function is used elsewhere, make sure it’s actually called or exported:
def _helper(x: int) -> int:
return x * 2
def main():
print(_helper(5))
Common Fixes & Workarounds
- Remove functions that are never called in your code.
- Use underscores (
_) for intentionally unused function parameters. - Use the
excludeproperty in your config to avoid analyzing unnecessary folders. - Add type hints and use explicit type annotations for clarity.
- Disable
reportUnusedFunctionfor private functions if needed to avoid false positives. - Refer to the Pyright configuration documentation for details on configuring or disabling this diagnostic.
See Also
python.analysis.diagnosticSeverityOverrides— adjust or suppress this diagnosticpython.analysis.typeCheckingMode— controls which diagnostics are enabled by default