259 karma · joined Feb 19, 2013 (13y ago) · 43 submissions
comment 8mo ago · link · parent
def _(flag: bool):
if flag:
x = True
...
if flag:
read(x)
But it's easy to turn the rule on if you want it: [tool.ty.rules]
possibly-unresolved-reference = "error"comment 11mo ago · link · parent
comment 1y ago · link · parent
x = [] # list[Unknown]
x.append(A()) # list[Unknown | A]
takes_list_of_a_or_b(x) # list[A | B]
We haven't decided yet if this is what we want to do, though. It's also possible that we may decide to compromise on the gradual guarantee in this area. It's not an ironclad rule for us, just something we're considering as a factor.comment 1y ago · link · parent
In your example, wouldn't `none()` be a type for `x` that satisfies both `Integer.to_string(x)` and `Atom.to_string(x)`? Or do you special-case `none()` and error if it occurs?
comment 1y ago · link · parent
comment 1y ago · link · parent
comment 1y ago · link · parent
It will certainly be slower than Ruff, just because multi-file type analysis more complex and less embarrassingly parallel than single-file linting.
comment 1y ago · link · parent
Currently we default to our oldest supported Python version, in which `datetime.UTC` really doesn't exist! Use `--python-version 3.12` on the CLI, or add a `ty.toml` with e.g.
``` [environment] python-version = "3.12" ```
And we'll find `datetime.UTC`.
We've discussed that this is probably the wrong default, and plan to change it.
comment 5y ago · link · parent
comment 5y ago · link · parent
Our approach to “int fits in a machine word” in Static Python is to require machine ints to be explicitly annotated as such, and then you opt in to limited size ints with overflow etc, in exchange for getting really fast arithmetic.
comment 5y ago · link · parent
We haven’t gone the hidden classes route so far because it’s simpler to just look at attributes assigned in __init__ and annotated on the class and lock those into slots. If you’re writing typed Python you probably don’t do a lot of tacking extra ad hoc attributes onto instances, since type checkers don’t like that either.
comment 5y ago · link · parent
comment 5y ago · link · parent
comment 5y ago · link · parent
Most of the hits are due to the default “JIT everything” behavior which is really bad if there are a lot of rarely called functions, but would be easy to fix. This is discussed in the README.