Skip to content

Conversation

@dandavison
Copy link
Contributor

@dandavison dandavison commented Jul 12, 2025

This is PR 1/5 in a stack.

Clean up typing with the aim of having zero type errors reported by pyright in IDE, enforced in CI.

@dandavison dandavison force-pushed the typing-cleanup branch 2 times, most recently from 31c31f3 to 58d2a77 Compare July 12, 2025 20:38
@dandavison dandavison changed the title Typing cleanup [1/4] Typing cleanup Jul 12, 2025

[tool.poe.tasks]
lint = [
{cmd = "uv run basedpyright src"},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The benefit of basedpyright is that it enforces precisely the set of diagnostics in pyproject.toml, when run as a CLI and when run via LSP. This allows SDK developers to choose to use an IDE setup that will match CI. (Cursor users don't have to do anything, they have no choice but to use a type checker based on basedpyright)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this commit we are checking src/ only; that is extended to tests in a subsequent PR.

@dandavison dandavison force-pushed the typing-cleanup branch 2 times, most recently from 6a5080c to daee4f6 Compare July 14, 2025 13:04

@dataclass_transform()
class _BaseTestCase:
pass
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm using dataclass_transform in tests to allow me to create classes of the form

class MyTestCaseClass:
    some_attr: Foo

MyTestCaseClass is never instantiated in my tests; it's syntactic/ergonomic convenience for a module to hold some nexus service definition.

My expectation was that @dataclass_transform could be used directly on the class, but it appears to only take effect when applied to a parent class.

@dandavison dandavison changed the title [1/4] Typing cleanup [1/5] Typing cleanup Jul 14, 2025
pyproject.toml Outdated
"poethepoet>=0.35.0",
"pydoctor>=25.4.0",
"pyright>=1.1.402",
"pyright==1.1.403",
Copy link

@cretz cretz Jul 14, 2025

Choose a reason for hiding this comment

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

Why fixate pyright here? Our users may have long since updated past this while we stay on this specific version so we won't catch new things. I don't necessarily mind it though if we keep on top of it.

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 was unintentional (resulted from me doing a thoughtless uv command: uv add --group dev pyright==$version.
Tbh I've mainly been doing this because pyright prints a noisy nagging notice to the terminal on uv sync.

I've changed it to pyright>=1.1

Copy link

Choose a reason for hiding this comment

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

It looks like we're going to get a lot of noise on PRs for stuff we have around for older Python. Maybe we should disable reportDeprecated for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I've done that now. It's a shame because I'd like the deprecation warnings in the IDE but I agree the PR noise it intolerable so this seems like the only option until we find another way around it.

AI: This commit should have tag name typing-cleanup and should be
force-pushed to a branch of that name as necessary.
@dandavison dandavison merged commit 54bee01 into main Jul 14, 2025
10 checks passed
@dandavison dandavison deleted the typing-cleanup branch July 14, 2025 15:54
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