Skip to content
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

Automatically rewrite NamedTuple and TypedDict with newer syntaxes #351

Closed
charliermarsh opened this issue Oct 7, 2022 · 5 comments
Closed
Labels
rule Implementing or modifying a lint rule

Comments

@charliermarsh
Copy link
Member

From pyupgrade:

Screen Shot 2022-10-07 at 4 04 06 PM

This could be a good use-case for the codegen module.

@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label Oct 7, 2022
@martinlehoux
Copy link
Contributor

I'll try this one if that's okay

@martinlehoux
Copy link
Contributor

martinlehoux commented Nov 13, 2022

A few questions on top of my mind @charliermarsh

  • Should we handle from typing import TypedDict as CustomTypedDict?
  • Should we handle MyType = TypedDict("MyType", dict(a=str, b=int))?
  • What should we do for MyType = TypedDict("OtherName", ...)?
  • And overall, do you think TypedDict rule and NamedTuple rule should be the same, or two different rules?

@charliermarsh
Copy link
Member Author

Good questions!

Should we handle from typing import TypedDict as CustomTypedDict?

Na, I think we should ignore (leave it unchanged).

Should we handle MyType = TypedDict("MyType", dict(a=str, b=int))?

I think it's fine not to handle this case. It'd be nice to include it, but I don't see it as a requirement.

What should we do for MyType = TypedDict("OtherName", ...)?

Let's ignore this case, if possible (leave it unchanged).

And overall, do you think TypedDict rule and NamedTuple rule should be the same, or two different rules?

I would vote for two different rules.

@martinlehoux
Copy link
Contributor

Regarding NamedTuples:

  • Support rename (that converts invalid identifiers to _<k> keys, and duplicated too) => I don't see a technical reason for why not, but doesn't seem very useful
  • Support defaults (that list fields defaults from right to left) => I guess this one is useful
  • Support module (I don't event know if possible with class) => I'd say we drop that

@charliermarsh
Copy link
Member Author

Completed by @martinlehoux! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

2 participants