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

False positive with TypedDict #127

Open
danjones1618 opened this issue May 10, 2024 · 2 comments
Open

False positive with TypedDict #127

danjones1618 opened this issue May 10, 2024 · 2 comments

Comments

@danjones1618
Copy link

danjones1618 commented May 10, 2024

When using with a TypeDict like:

class PaginationDict(TypedDict):
     prev: Optional[str]
     next: Optional[str]
     count: int
     data: any

This will incorrectly flag: A003 class attribute "next" is shadowing a Python builtin

These checks should be disabled when a class inherits from TypedDict

@gforcada
Copy link
Owner

Hi @danjones1618 thanks for using flake8-builtins and even more to take the time to report issues about it! 👍🏾

Oh, I see, indeed, that's a problematic corner case.

I myself do not use the typing module or typing in general unfortunately.

You have, at least 3 options:

  • add a flake8 ignore for this specific file/error
  • according to the docs you could define the dictionary like:
PaginationDict = TypeDict('PaginationDict', {'prev': Optional[str], 'next': Optional[str]})
  • provide a PR to fix the issue here
  • maybe other options?

Unfortunately I myself don't have much time free as of late...

@danjones1618
Copy link
Author

I've drafted a PR to start to fix this in #128 .

There is an edge case I foresee which will always raise a false positive.
This is when the developer inhertis from a TypedDict that is defined in another file as we won't be able to derrive the inheritence tree. I think this is a fair edge case to not handle.

The implementation I drafted does not resolve inheritence at the moment.
There is a seperate issue that comes to mind: it should validate that the TypedDict you inherit from does in fact come from the typing module.

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

No branches or pull requests

2 participants