Skip to content

Conversation

@AlexWaygood
Copy link
Member

Summary

It's fairly common in Python do to something like this:

import datetime

x: datetime

when you actually meant to do this:

import datetime

x: datetime.datetime

This PR adds subdiagnostics to hint to the user what the cause of the invalid-type-form error might be in cases like this.

Closes astral-sh/ty#373

Test Plan

Snapshots

@AlexWaygood AlexWaygood added ty Multi-file analysis & type inference diagnostics Related to reporting of diagnostics. labels May 21, 2025
@github-actions
Copy link
Contributor

github-actions bot commented May 21, 2025

mypy_primer results

No ecosystem changes detected ✅

@MichaReiser
Copy link
Member

you have to leave some diagnostic improvements to contributors ;)

…pe is used in a type expression and the module has a member which would be valid in a type expression
@AlexWaygood AlexWaygood force-pushed the alex/datetime-dot-datetime-diag branch from fdf2569 to bc9d7f8 Compare May 21, 2025 17:07
Comment on lines 60 to 62
Copy link
Contributor

@InSyncWithFoo InSyncWithFoo May 21, 2025

Choose a reason for hiding this comment

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

Not something directly related to this PR, but these info lines are inconsistent in their capitalizations and punctuations.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

Copy link
Contributor

@InSyncWithFoo InSyncWithFoo May 21, 2025

Choose a reason for hiding this comment

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

And I'd argue that the message is a bit awkwardly phrased. How about this?

Did you mean to use its member Image.Image instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a nice shortening, thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member Author

Choose a reason for hiding this comment

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

Not something directly related to this PR, but these info lines are inconsistent in their capitalizations and punctuations.

(I agree that this is inconsistent, but I don't plan to address it in this PR since it predates this PR)

@AlexWaygood AlexWaygood merged commit 02394b8 into main May 21, 2025
35 checks passed
@AlexWaygood AlexWaygood deleted the alex/datetime-dot-datetime-diag branch May 21, 2025 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Related to reporting of diagnostics. ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error[invalid-type-form]: Variable of type <module 'PIL.Image'> is not allowed in a type expression

6 participants