Skip to content

Optimize API for type checking with ty #12442

@RubenVanEldik

Description

@RubenVanEldik

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

Astral, the team behind Ruff, have created a new type checker called ty.

I am not completly sure if this is an issue with ty or Streamlit, but currently ty raises an error for st.stop() as it does not think the code will never return st.stop(). ty is rapidly gaining popularity, so I think it would be good to figure out what goes wrong here. I have tried to troubleshoot it, but I am not familiar enough with the inner workings of Streamlit.

import typing

import streamlit as st

def my_func() -> typing.NoReturn:
    st.write("Hello world")
    st.stop()

my_func()
error[invalid-return-type]: Function always implicitly returns `None`, which is not assignable to return type `Never`
 --> main.py:5:18
  |
3 | import streamlit as st
4 |
5 | def my_func() -> typing.NoReturn:
  |                  ^^^^^^^^^^^^^^^
6 |     st.write("Hello world")
7 |     st.stop()
  |
info: Consider changing the return annotation to `-> None` or adding a `return` statement
info: rule `invalid-return-type` is enabled by default

Found 1 diagnostic

Reproducible Code Example

Steps To Reproduce

No response

Expected Behavior

No response

Current Behavior

No response

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version:
  • Python version:
  • Operating System:
  • Browser:

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:typingIssues and enhancements related to API typingfeature:st.stopRelated to `st.stop` commandtype:enhancementRequests for feature enhancements or new features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions