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 positives for "Attempted to reuse member name in Enum" #11971

Closed
mrossinek opened this issue Jan 11, 2022 · 0 comments
Closed

False positives for "Attempted to reuse member name in Enum" #11971

mrossinek opened this issue Jan 11, 2022 · 0 comments
Labels
bug mypy got something wrong topic-enum

Comments

@mrossinek
Copy link
Contributor

Bug Report

False positives for Enum member reuse attempts when an Enum has a large number of entries.
I first encountered this issue here

To Reproduce

Unfortunately, I have not yet found a minimal reproducing example.

  1. Clone https://gitlab.com/mrossinek/cobib
  2. Run mypy --strict src/cobib/config/event.py with mypy -V >= 0.930

Expected Behavior

No errors should occur.

Actual Behavior

I obtain the following errors:

src/cobib/config/event.py:137: error: Attempted to reuse member name "PostAddCommand" in Enum definition "Event"  [misc]
src/cobib/config/event.py:222: error: Attempted to reuse member name "PostImportCommand" in Enum definition "Event"  [misc]
src/cobib/config/event.py:445: error: Attempted to reuse member name "PostBibtexParse" in Enum definition "Event"  [misc]
src/cobib/config/event.py:498: error: Attempted to reuse member name "PostYAMLParse" in Enum definition "Event"  [misc]
src/cobib/config/event.py:551: error: Attempted to reuse member name "PostArxivParse" in Enum definition "Event"  [misc]
src/cobib/config/event.py:578: error: Attempted to reuse member name "PostDOIParse" in Enum definition "Event"  [misc]
src/cobib/config/event.py:605: error: Attempted to reuse member name "PostISBNParse" in Enum definition "Event"  [misc]
src/cobib/config/event.py:632: error: Attempted to reuse member name "PostURLParse" in Enum definition "Event"  [misc]
src/cobib/config/event.py:663: error: Attempted to reuse member name "PostZoteroImport" in Enum definition "Event"  [misc]

Your Environment

  • Mypy version used: 0.930 and 0.931
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files):
[mypy]
python_version = 3.7
show_error_codes = True
warn_return_any = True
warn_unused_configs = True
  • Python version used: 3.10.1
  • Operating system and version: Arch Linux, 5.15.13-arch1-1 as well as in the python:latest Docker container

More information

I believe that this bug was introduced as part of #11267. It introduced the following line: https://github.com/python/mypy/blob/48d810d/mypy/semanal.py#L2874
Instead, I would expect this line to look more like https://github.com/python/mypy/blob/48d810d/mypy/semanal.py#L453 (i.e. also allow PlaceholderNode objects.

The reason that I believe this to be necessary is open inspecting the runtime data during the offending scenarios. There I was able to extract the following names: SymbolTable object:

SymbolTable(
  PostAddCommand : Mdef/PlaceholderNode (cobib.config.event.Event.PostAddCommand)
  PostArxivParse : Mdef/PlaceholderNode (cobib.config.event.Event.PostArxivParse)
  PostBibtexDump : Mdef/Var (cobib.config.event.Event.PostBibtexDump) : cobib.config.event.Event
  PostBibtexParse : Mdef/PlaceholderNode (cobib.config.event.Event.PostBibtexParse)
  PostDOIParse : Mdef/PlaceholderNode (cobib.config.event.Event.PostDOIParse)
  PostDeleteCommand : Mdef/Var (cobib.config.event.Event.PostDeleteCommand) : cobib.config.event.Event
  PostEditCommand : Mdef/Var (cobib.config.event.Event.PostEditCommand) : cobib.config.event.Event
  PostExportCommand : Mdef/Var (cobib.config.event.Event.PostExportCommand) : cobib.config.event.Event
  PostFileDownload : Mdef/Var (cobib.config.event.Event.PostFileDownload) : cobib.config.event.Event
  PostGitCommit : Mdef/Var (cobib.config.event.Event.PostGitCommit) : cobib.config.event.Event
  PostISBNParse : Mdef/PlaceholderNode (cobib.config.event.Event.PostISBNParse)
  PostImportCommand : Mdef/PlaceholderNode (cobib.config.event.Event.PostImportCommand)
  PostInitCommand : Mdef/Var (cobib.config.event.Event.PostInitCommand) : cobib.config.event.Event
  PostListCommand : Mdef/Var (cobib.config.event.Event.PostListCommand) : cobib.config.event.Event
  PostModifyCommand : Mdef/Var (cobib.config.event.Event.PostModifyCommand) : cobib.config.event.Event
  PostOpenCommand : Mdef/Var (cobib.config.event.Event.PostOpenCommand) : cobib.config.event.Event
  PostRedoCommand : Mdef/Var (cobib.config.event.Event.PostRedoCommand) : cobib.config.event.Event
  PostSearchCommand : Mdef/Var (cobib.config.event.Event.PostSearchCommand) : cobib.config.event.Event
  PostShowCommand : Mdef/Var (cobib.config.event.Event.PostShowCommand) : cobib.config.event.Event
  PostURLParse : Mdef/PlaceholderNode (cobib.config.event.Event.PostURLParse)
  PostUndoCommand : Mdef/Var (cobib.config.event.Event.PostUndoCommand) : cobib.config.event.Event
  PostYAMLDump : Mdef/Var (cobib.config.event.Event.PostYAMLDump) : cobib.config.event.Event
  PostYAMLParse : Mdef/PlaceholderNode (cobib.config.event.Event.PostYAMLParse)
  PostZoteroImport : Mdef/PlaceholderNode (cobib.config.event.Event.PostZoteroImport)
  PreAddCommand : Mdef/Var (cobib.config.event.Event.PreAddCommand) : cobib.config.event.Event
  PreArxivParse : Mdef/Var (cobib.config.event.Event.PreArxivParse) : cobib.config.event.Event
  PreBibtexDump : Mdef/Var (cobib.config.event.Event.PreBibtexDump) : cobib.config.event.Event
  PreBibtexParse : Mdef/Var (cobib.config.event.Event.PreBibtexParse) : cobib.config.event.Event
  PreDOIParse : Mdef/Var (cobib.config.event.Event.PreDOIParse) : cobib.config.event.Event
  PreDeleteCommand : Mdef/Var (cobib.config.event.Event.PreDeleteCommand) : cobib.config.event.Event
  PreEditCommand : Mdef/Var (cobib.config.event.Event.PreEditCommand) : cobib.config.event.Event
  PreExportCommand : Mdef/Var (cobib.config.event.Event.PreExportCommand) : cobib.config.event.Event
  PreFileDownload : Mdef/Var (cobib.config.event.Event.PreFileDownload) : cobib.config.event.Event
  PreGitCommit : Mdef/Var (cobib.config.event.Event.PreGitCommit) : cobib.config.event.Event
  PreISBNParse : Mdef/Var (cobib.config.event.Event.PreISBNParse) : cobib.config.event.Event
  PreImportCommand : Mdef/Var (cobib.config.event.Event.PreImportCommand) : cobib.config.event.Event
  PreInitCommand : Mdef/Var (cobib.config.event.Event.PreInitCommand) : cobib.config.event.Event
  PreListCommand : Mdef/Var (cobib.config.event.Event.PreListCommand) : cobib.config.event.Event
  PreModifyCommand : Mdef/Var (cobib.config.event.Event.PreModifyCommand) : cobib.config.event.Event
  PreOpenCommand : Mdef/Var (cobib.config.event.Event.PreOpenCommand) : cobib.config.event.Event
  PreRedoCommand : Mdef/Var (cobib.config.event.Event.PreRedoCommand) : cobib.config.event.Event
  PreSearchCommand : Mdef/Var (cobib.config.event.Event.PreSearchCommand) : cobib.config.event.Event
  PreShowCommand : Mdef/Var (cobib.config.event.Event.PreShowCommand) : cobib.config.event.Event
  PreURLParse : Mdef/Var (cobib.config.event.Event.PreURLParse) : cobib.config.event.Event
  PreUndoCommand : Mdef/Var (cobib.config.event.Event.PreUndoCommand) : cobib.config.event.Event
  PreYAMLDump : Mdef/Var (cobib.config.event.Event.PreYAMLDump) : cobib.config.event.Event
  PreYAMLParse : Mdef/Var (cobib.config.event.Event.PreYAMLParse) : cobib.config.event.Event
  PreZoteroImport : Mdef/Var (cobib.config.event.Event.PreZoteroImport) : cobib.config.event.Event
  __new__ : Mdef/FuncDef (cobib.config.event.Event.__new__) : def (cls: Any, annotation: Any?) -> Event?
  _annotation_ : Mdef/Var (cobib.config.event.Event._annotation_) : Any
  fire : Mdef/FuncDef (cobib.config.event.Event.fire) : def (self: Any, *args: Any?, **kwargs: Any?) -> Any?
  subscribe : Mdef/FuncDef (cobib.config.event.Event.subscribe) : def (self: Any, function: Callable?) -> Callable?
  validate : Mdef/FuncDef (cobib.config.event.Event.validate) : def (self: Any) -> bool?
)

This is just prior to this error being raised:

Attempted to reuse member name "PostAddCommand" in Enum definition "Event"

The following are the lvalue and names[name] at this specific occurrence.

NameExpr(PostAddCommand) Mdef/PlaceholderNode (cobib.config.event.Event.PostAddCommand)

I am going to open a PR in a second with a suggestion to fix this by also allowing PlaceholderNode objects.

@mrossinek mrossinek added the bug mypy got something wrong label Jan 11, 2022
mrossinek added a commit to mrossinek/mypy that referenced this issue Jan 11, 2022
Allows PlaceholderNode objects before raising an error for the attempted
reuse of a member name inside an Enum.
@mrossinek mrossinek mentioned this issue Jan 11, 2022
mrossinek added a commit to mrossinek/mypy that referenced this issue Jan 13, 2022
mrossinek added a commit to mrossinek/cobib that referenced this issue Jan 13, 2022
Revert this once python/mypy#11972 is merged and
released.
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this issue Jan 20, 2022
Allows PlaceholderNode objects before raising an error for the attempted
reuse of a member name inside an Enum.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-enum
Projects
None yet
Development

No branches or pull requests

2 participants