Skip to content

Ensure instances of CallableType can always be hashed - #12741

Merged
JelleZijlstra merged 1 commit into
python:masterfrom
AlexWaygood:typeddict-crash
May 8, 2022
Merged

JelleZijlstra merged 1 commit into
python:masterfrom
AlexWaygood:typeddict-crash

Conversation

@AlexWaygood

Copy link
Copy Markdown
Member

Description

Trying to hash an instance of mypy.types.CallableType will crash if self.fallback.type is a FakeInfo. Apparently this is the case if the CallableType represents a classmethod alternative constructor on a TypedDict. Such alternative-constructor methods aren't currently supported by mypy, but mypy also shouldn't crash if it comes across them.

Fixes #5653 (though I'm not 100% sure if this is the best solution).

Test Plan

Test case added to check-typeddict.test.

@github-actions

github-actions Bot commented May 7, 2022

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure this is the greatest solution either, but it works and fixes the crash.

@JelleZijlstra
JelleZijlstra merged commit 49d5cc9 into python:master May 8, 2022
@AlexWaygood
AlexWaygood deleted the typeddict-crash branch May 8, 2022 05:08
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.

Crash on definition of TypedDict method

2 participants