-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash on definition of TypedDict method #5653
Comments
Also, when used as a var-keyword param, TypedDict doesn't work as I'd expect it to: class LoginParams(TypedDict):
emailAddress: str
password: str
async def resolve_login(
root: None, info: GraphQLResolveInfo, ctx: Context, **params: LoginParams
) -> typing.Optional[UserType]:
user = get_user_by_email_address(params['not_emailAddress']) # does not warn I noticed there is a dedicated type |
@dfee Looks like it's explicitly proscribed in PEP 589:
Doesn't really address the rationale. I couldn't find any discussion about this (or much else, for that matter) in the PR for PEP589 or the typing-sig mailing list. Maybe someone else knows the story? |
@dfee @erickpeirson Only class methods accessed on class object work, normal methods will not work at runtime. We can of course allow specifically this case, but this is quite niche and therefore low-priority. (The |
The crash reproduces on mypy 0.950 with this code snippet: from typing import TypedDict
class RowProxy:
first_name: str
last_name: str
class User(TypedDict, total=False):
firstName: str
lastName: str
@classmethod
def from_row(cls, row: RowProxy) -> "User":
return User(firstName=row.first_name, lastName=row.last_name) mypy traceback:
|
There are really two issues here:
|
The crash has existed since mypy 0.710, which is the earliest version of mypy that recognises |
Interesting, it looks like the traceback on master is slightly different:
|
The classmethod is represented internally in mypy as a In I can see three options here:
I'm inclined towards Option (1), because I feel like something unusual is almost certainly going on if |
We've now fixed the crash. |
I'm not sure if this is a bug or a feature, but I was considering migrating from NamedTuple to TypedDict, and ran into a problem where methods don't seem to be supported on TypedDicts.
Despite the error, the code runs fine. So, I'm looking for clarification that this is / isn't a bug, and maybe some reasoning about
The text was updated successfully, but these errors were encountered: