Skip to content

upcoming: Ty, Pyrefly #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks
bennn opened this issue May 28, 2025 · 0 comments
Open
3 tasks

upcoming: Ty, Pyrefly #21

bennn opened this issue May 28, 2025 · 0 comments

Comments

@bennn
Copy link
Member

bennn commented May 28, 2025

There are 2 fast new typecheckers coming to Python:

Quick comparison:

Notes:

class WithX:
  x: int

@final
class Other:
  pass

def foo(obj: WithX | Other):
  if hasattr(obj, "x"):
    # ➖ pyrefly | revealed type: Other | WithX
    # ✅ ty.     | Revealed type: `WithX`
    # ➖ mypy.   | Revealed type is "Union[__main__.WithX, __main__.Other]"
    # ➖ pyright | Type of "obj" is "WithX | Other"
    reveal_type(obj)
  • Q. Is ty sound for property methods? Go back to the static python example.
class MyClass:
    ...

class MySubclass(MyClass):
    ...

def bar(obj: MyClass):
    if not isinstance(obj, MySubclass):
        # ➖ pyrefly | revealed type: MyClass
        # ✅ ty.     | Revealed type: `MyClass & ~MySubclass`
        # ➖ mypy.   | Revealed type is "__main__.MyClass"
        # ➖ pyright | Type of "obj" is "MyClass"
        reveal_type(obj)
  • Q. How set-theoretic are ty types? Is A & -B equal to -B & A ?

  • Q. Ty aspires to the gradual guarantee. I bet there are counterexamples, but then again Carl Meyer is involved and he knows all about why Static Python broke the gradual guarantees!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant