Skip to content

Detect duplicate branch definitions#543

Open
JelleZijlstra wants to merge 2 commits into
PyCQA:mainfrom
JelleZijlstra:duplicate-branches
Open

Detect duplicate branch definitions#543
JelleZijlstra wants to merge 2 commits into
PyCQA:mainfrom
JelleZijlstra:duplicate-branches

Conversation

@JelleZijlstra
Copy link
Copy Markdown
Collaborator

@JelleZijlstra JelleZijlstra commented May 9, 2026

Adds Y069 to flag definitions that are identical across sibling sys.version_info or sys.platform branches. Non-consecutive duplicates in 3+-branch version chains are ignored so newest-first ordering can be preserved.

Some known issues in typeshed are fixed in python/typeshed#15743.

Remaining typeshed hits from this check:

  • stdlib/ast.pyi:769 - overlapping ImportFrom.__init__ overload shared by adjacent version branches. Deduplicating this would probably make the code harder to follow.
  • stdlib/pathlib/__init__.pyi:160 - Path.__new__ is identical except for a pyright ignore comment, which is ignored by AST comparison.
  • stdlib/tkinter/__init__.pyi:791, stdlib/tkinter/__init__.pyi:822 - wm_attributes platform overload sets partially overlap. Hard to fix without making the code harder to follow
  • stubs/pyinstaller/PyInstaller/building/api.pyi:33 - _IconParam is the same for win32 and darwin while _Icon differs.

This found a few useful things, but also has false positives. It may be worth doing to protect against issues in future PRs, but curious to hear other opinions.

@github-actions

This comment has been minimized.

@JelleZijlstra JelleZijlstra marked this pull request as ready for review May 9, 2026 17:21
@srittau srittau closed this May 11, 2026
@srittau srittau reopened this May 11, 2026
@github-actions
Copy link
Copy Markdown

⚠ Flake8 diff showing the effect of this PR on typeshed:

> ./stdlib/ast.pyi:769:9: Y069 Definition "__init__" is identical in multiple sys.version_info/sys.platform branches
> ./stdlib/pathlib/__init__.pyi:158:9: Y069 Definition "__new__" is identical in multiple sys.version_info/sys.platform branches
> ./stdlib/sysconfig.pyi:52:5: Y069 Definition "is_python_build" is identical in multiple sys.version_info/sys.platform branches
> ./stdlib/tkinter/__init__.pyi:792:9: Y069 Definition "wm_attributes" is identical in multiple sys.version_info/sys.platform branches
> ./stdlib/tkinter/__init__.pyi:823:13: Y069 Definition "wm_attributes" is identical in multiple sys.version_info/sys.platform branches
> ./stubs/pyinstaller/PyInstaller/building/api.pyi:33:5: Y069 Definition "_IconParam" is identical in multiple sys.version_info/sys.platform branches

@srittau
Copy link
Copy Markdown
Member

srittau commented May 11, 2026

While I think this is useful to run from time to time, considering the substantial amount of false positives, I suggest to move this to the "not enabled by default" section of error codes.

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.

2 participants