Skip to content

sys.exit is not being acknowledged as an exit point of the function #454

Closed as duplicate

Description

@inoa-jboliveira

Summary

I don't know how to describe it exactly, but running ty check on the following code shows an invalid-return-type because the code does not acknowledges that sys.exit is equivalent o a raise SystemExit and thus the function will not return anything.

def config(thing) -> dict:
    if thing:
        return {'response': thing}
    sys.exit(-1)

This is a dumbed down version of a real function on a real codebase, where the code exits if some config is not passed correctly. In all successful function calls, it will return a dict otherwise it will raise SystemExit. There is no possible "None" being returned as suggested:

error[invalid-return-type]: Function can implicitly return `None`, which is not assignable to 
return type `dict[Unknown, Unknown]`
 --> foo.py:4:17
  |
4 | def config(thing) -> dict:
  |                      ^^^^
5 |     if thing:
6 |         return {'response': thing}
  |

Version

ty 0.0.1-alpha.5 (3b726d8 2025-05-17)

Activity

  1. transferred this issue fromastral-sh/ruffon May 19, 2025
  2. changed the title [-][ty] sys.exit is not being acknowledged as an exit point of the function[/-] [+]`sys.exit` is not being acknowledged as an exit point of the function[/+] on May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions