Skip to content

invalid-return-type error message is too weak for wrong return type #538

@konstin

Description

@konstin

Summary

Playground link: https://play.ty.dev/95591965-0266-4a59-9952-4e8be99ee67c

from pathlib import Path

def setup_test_project(registry_name: str, registry_url: str, project_dir: str) -> Path:
    pyproject_file = Path(project_dir) / "pyproject.toml"
    pyproject_file.write_text("...", encoding="utf-8")

The error to me implies that I need to use None | Path when the function can never return Path at all and I should replaced Path with None instead

error[invalid-return-type]: Function can implicitly return `None`, which is not assignable to return type `Path`
  --> script.py:64:84
   |
64 | def setup_test_project(registry_name: str, registry_url: str, project_dir: str) -> Path:
   |                                                                                    ^^^^
65 |     pyproject_file = Path(project_dir) / "pyproject.toml"
66 |     pyproject_file.write_text("...", encoding="utf-8")
   |
info: rule `invalid-return-type` is enabled by default

Version

ty 0.0.1-alpha.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    diagnosticsRelated to reporting of diagnostics.help wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions