Skip to content

os.path functions get wrong type assignments. #405

@Michallote

Description

@Michallote

Summary

Minimum code fail:

#fail.py
import os

def get_rel(output_directory: str) -> str:
    assert os.path.exists(
        output_directory
    ), f"Output directory '{output_directory}' does not exist. Create the folder and try again."
    output_directory = os.path.relpath(output_directory)
    return output_directory

And running in the terminal:

$ uvx ty check fail.py
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
error[invalid-assignment]: Object of type `bytes` is not assignable to `str`
  --> fail.py:9:5
   |
 7 |         output_directory
 8 |     ), f"Output directory '{output_directory}' does not exist. Create the folder and try again."
 9 |     output_directory = os.path.relpath(output_directory)
   |     ^^^^^^^^^^^^^^^^
10 |     return output_directory
   |
info: rule `invalid-assignment` is enabled by default

Found 1 diagnostic

commenting os.path.exists does not change the outcome.

Version

ty 0.0.1-alpha.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions