Skip to content

Conversation

@kracekumar
Copy link
Contributor

@kracekumar kracekumar commented Dec 17, 2025

Description

  1. The goal of the PR is to introduce ty as default type checker while deprecating mypy.
  2. So far all the changes in the PR is meant to satisfy the ty checker. It is stricter and highly opinionated. So far the changes seems to be straight forward but required a re-factoring, adding ignore statements, changing types to appropriate types.
  3. You can run ty by
$uv run ty check
All checks passed!
  1. Performance of mypy vs ty
kracekumar@Mac ~/c/litecli (krace/ty)> time uv run ty check -v
INFO Defaulting to python-platform `darwin`
INFO Python version: Python 3.9, platform: darwin
INFO Indexed 25 file(s) in 0.003s
All checks passed!

________________________________________________________
Executed in  116.63 millis    fish           external
   usr time  224.67 millis    0.11 millis  224.56 millis
   sys time   69.86 millis    1.10 millis   68.76 millis

kracekumar@Mac ~/c/litecli (krace/ty)> time uv run mypy .
litecli/__init__.py: error: Source file found twice under different module names: "litecli" and "litecli.__init__"
litecli/__init__.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
litecli/__init__.py: note: Common resolutions include: a) adding `__init__.py` somewhere, b) using `--explicit-package-bases` or adjusting MYPYPATH
Found 1 error in 1 file (errors prevented further checking)

________________________________________________________
Executed in  859.16 millis    fish           external
   usr time  185.33 millis    0.17 millis  185.16 millis
   sys time  101.28 millis    2.51 millis   98.77 millis

kracekumar@Mac ~/c/litecli (krace/ty) [2]>
  1. The pyproject.yamlcontains minimal configuration for ty.
  2. Here is the amp thread to replace, ty: ignore to type: ignore.

Checklist

  • I've added this contribution to the CHANGELOG.md file.

@kracekumar kracekumar changed the title [WIP - Do Not Merge]: Add the version to get ty working [WIP - Do Not Merge]: Add ty type checking Dec 19, 2025

# map Pygments tokens (ptk 1.0) to class names (ptk 2.0).
TOKEN_TO_PROMPT_STYLE: dict[Token, str] = {
TOKEN_TO_PROMPT_STYLE: dict[_TokenType, str] = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mapping to accurate type so ty doesn't complain.

from litecli import __file__ as package_root

package_root = os.path.dirname(package_root)
package_root = os.path.dirname(str(package_root))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty doesn't like package_root as it comes from import reference, hence converting to string.

litecli/main.py Outdated

try:
from sqlean import OperationalError, sqlite_version
from sqlean import OperationalError, sqlite_version # ty: ignore[unresolved-import]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sqlean has no type definitions, hence need to ignore all places. At runtime, the methods are available.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe create types for sqlean.

"all_punctuations": re.compile(r"([^\s]+)$"),
}

LAST_WORD_INCLUDE_TYPE = Literal["alphanum_underscore", "many_punctuations", "most_punctuations", "all_punctuations"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty later complains the value passed is str and so declare and import later.

write_once,
write_pipe_once,
close_tee,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty doesn't like when these methods are accessed like special.xyz()when it is missing in the init.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be scope to improve over all import systems.

self.config = config

def list(self) -> list[str]:
def list(self) -> builtins.list[str]:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty is opinionated about this. astral-sh/ty#2035

fuzzy: bool = True,
casing: str | None = None,
punctuations: str = "most_punctuations",
punctuations: LAST_WORD_INCLUDE_TYPE = "most_punctuations",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the puncutations value is literal and here it was declared as str, ty complains about it. hence use the same type here.

@kracekumar kracekumar changed the title [WIP - Do Not Merge]: Add ty type checking Migrate typechecking to ty Dec 21, 2025
callbacks = [callbacks]
callbacks_list: list[Callable] = [callbacks]
else:
callbacks_list = list(cast(list[Callable], callbacks))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty was complaining about this, hence modified it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird. Wouldn't this work?

callbacks_list = ist(callbacks)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from .sqlcompleter import SQLCompleter
from .sqlexecute import SQLExecute

click.disable_unicode_literals_warning = True
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer needed in Python 3.9

write_once,
write_pipe_once,
close_tee,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be scope to improve over all import systems.

@@ -0,0 +1 @@

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use relative imports in tests, added init.py file. Rather than using from utils import xyzuse from .utils import xyz.

style = style_factory("default", cli_style)

assert isinstance(style(), Style)
assert isinstance(style, Style)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this wasn't caught earlier.

(".import ./data.csv ", 2),
(".import ./data.csv t", 2),
(".import ./data.csv `t", 2),
('.import ./data.csv "t', 2),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making it as tuple is easier to annotate the types.

("598244", "6 days 22 hours 10 min 44 sec"),
("522600", "6 days 1 hour 10 min 0 sec"),
]:
assert human_readable_text == format_uptime(seconds)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making it easier.

return ["test"]

class PromptBuffer:
class PromptBuffer(PromptSession):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to satisfy ty. Since PromptSession contains output attribute.


def test_startup_commands(executor):
m = LiteCli(liteclirc=default_config_file)
assert m.startup_commands
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to ensure, later access satisfies type checker.

@kracekumar
Copy link
Contributor Author

There are some more generic Python typing improvements that are possible. I can send a separate PR later.

Can you take a look the changes @amjith @rolandwalker ? Thank you!

@kracekumar kracekumar requested a review from amjith December 21, 2025 14:22
@kracekumar kracekumar merged commit eea974f into main Dec 22, 2025
8 checks passed
@kracekumar kracekumar deleted the krace/ty branch December 22, 2025 19:16
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

Successfully merging this pull request may close these issues.

3 participants