News for hackers. Stuff that matters.
Re:Pyrefly: Python type checker and language server in Rust by pawelkobojek on Tuesday October 14, 2025 @09:16AM (#45579650)
I love the speed advantage of pyrefly over (based)pyright but so far it doesn't seem to highlight as much as pyright does, for example it doesn't catch unreachable code like this:

  def fn(x: str):
    if x is None:
      x = "123"  # pyright flags that as unreachable code, pyrefly does not
Autocomplete for modules also doesn't work for me yet:

  import os
  os.  # I'll get `ABC, `Any`, `AnyStr`, `AnyStr_co`, `BinaryIO`, ...
Looking forward to have a fast language server for python though, pyright is way too slow for large projects.
Re:Pyrefly: Python type checker and language server in Rust by giancarlostoro on Tuesday October 14, 2025 @09:54AM (#45580088)
It's funny because in other typed languages a string can be null because of string being a reference type as opposed to a value type. I think Python type hints make more sense than C# does in this respect, which gives me a chuckle (two of my favorite languages and the untyped one makes more sense with types). That said, not sure if you already have but I would add a github issue / ticket reporting your issue to raise awareness to the devs.
Re:Pyrefly: Python type checker and language server in Rust by seabrookmx on Tuesday October 14, 2025 @11:52AM (#45581498)
If you use the nullable types compiler option in C# (which defaults to enabled for new projects) then you need to declare you string as string? for it to be nullable :)
Re:Pyrefly: Python type checker and language server in Rust by pjmlp on Wednesday October 15, 2025 @04:39AM (#45589657)
Yes, but you also need to turn the warning into an error for it to be actually usable, because .NET team didn't want to break the ecosystem, plenty of Assemblies out there didn't cared to update themselves.

I still have to disable nullable types in some delivery projects.

Re:Pyrefly: Python type checker and language server in Rust by kstrauser on Tuesday October 14, 2025 @10:43AM (#45580672)
A quibble: Python is strongly typed. It’s not un-typed in any reasonable sense of the word. It’s dynamically typed, though: type information is on objects, not on the names referring to them.
Re:Pyrefly: Python type checker and language server in Rust by Scarblac on Tuesday October 14, 2025 @10:31AM (#45580511)
All Python types are reference types. The reference to None isn't included in the str type.

There's no way to get an actual null reference, afaik. Variables always have some value, possibly None.

(not sure what happens if you set a reference to null from C - a crash, probably?)

Re:Pyrefly: Python type checker and language server in Rust by _flux on Tuesday October 14, 2025 @10:13AM (#45580252)
In some other typed languages, that is. E.g. in C++, OCaml, Haskell, F#, Kotlin, and Rust (a non-exhaustive list) you can have non-nullable strings, and other objects.
Re:Pyrefly: Python type checker and language server in Rust by asplake on Tuesday October 14, 2025 @10:37AM (#45580594)
It’s worth noting that even though the runtime allows nulls (i.e. None) anywhere, Python type checkers do distinguish between optional and mandatory types.
Re:Pyrefly: Python type checker and language server in Rust by scuff3d on Wednesday October 15, 2025 @01:05AM (#45588264)
In Zig you have to mark variables as nullable when they are declared. If you try to assign null to any variable that doesn't have it marked as such the program won't compile.

Any nullable type has to be unwrapped before accessing the value, or again, won't compile.

Re:Pyrefly: Python type checker and language server in Rust by mixmastamyk on Tuesday October 14, 2025 @01:27PM (#45582630)
The billion dollar mistake.
Re:Pyrefly: Python type checker and language server in Rust by parhamn on Tuesday October 14, 2025 @09:42AM (#45579952)
Whats the expected error in the example you gave? That x can't be none because it was received as a str?
Re:Pyrefly: Python type checker and language server in Rust by wiz21c on Tuesday October 14, 2025 @10:29AM (#45580488)
isn't it perfectly valid to pass None to that function ? It's not like python enforces types at runtime nor at compile time. Right ?
Re:Pyrefly: Python type checker and language server in Rust by Austizzle on Tuesday October 14, 2025 @10:47AM (#45580739)
It's not valid from a typing perspective, but python will let you. If you want to disregard types though then none of this matters anyway and you won't get much benefit from these tools
Re:Pyrefly: Python type checker and language server in Rust by yesb on Tuesday October 14, 2025 @10:54AM (#45580828)
Sure, it's valid python to do that. By that logic you could also pass an int. But the context of this post is that you're using a static type checker.
Re:Pyrefly: Python type checker and language server in Rust by robertlagrant on Tuesday October 14, 2025 @09:45AM (#45579977)
Yes, exactly. x would have to be str | None to be reachable.
Re:Pyrefly: Python type checker and language server in Rust by pawelkobojek on Tuesday October 14, 2025 @09:45AM (#45579974)
Exactly - something along the lines of "Statement is unreachable".
Re:Pyrefly: Python type checker and language server in Rust by boxed on Tuesday October 14, 2025 @09:44AM (#45579970)
Or that x is unused?
Re:Pyrefly: Python type checker and language server in Rust by veber-alex on Tuesday October 14, 2025 @09:39AM (#45579914)
Yeah I have a similar experience with ty.

Looks like none of these new type checkers are ready yet.

Re:Pyrefly: Python type checker and language server in Rust by f311a on Tuesday October 14, 2025 @09:44AM (#45579965)
Ty has autocomplete for imports, but it's hidden behind a toggle right now. They are still working on it. They index all the modules and functions, so you can just type the function name and it will suggest the correct import and insert it.
Re:Pyrefly: Python type checker and language server in Rust by kinto on Tuesday October 14, 2025 @01:01PM (#45582352)
Hey, Pyrefly developer here, thanks for trying us out! Thanks for bearing with us with these issues you're experiencing while we're still in alpha.

We're planning on adding unreachable code diagnostics soon (github issue [here](https://github.com/facebook/pyrefly/issues/1292)). These come for free with Pyright so we don't want to regress features.

I'm happy to help diagnose/fix your autocomplete issue: it should work on modules. If you want to provide details here, on [discord](https://discord.gg/Cf7mFQtW7W), or as a Github issue (github/discord preferred) we'll fix it for you + anyone else with the problem.

Re:Pyrefly: Python type checker and language server in Rust by pawelkobojek on Tuesday October 14, 2025 @02:25PM (#45583170)
I absolutely understand this is still alpha so I kind of assumed these are expected. Frankly, that's why I haven't submitted an issue -- I assumed it's going to be fixed at some point. I'll go ahead and make an issue on GitHub, thanks.