KEMBAR78
Handle union types when binding self by ilevkivskyi · Pull Request #18867 · python/mypy · GitHub
Skip to content

Conversation

ilevkivskyi
Copy link
Member

Currently we only bind self if the type is callable, but we actually should do this for all callable items in a union.

This use case is probably quite niche (since adding an annotation makes a variable an instance variable, and we rarely infer unions). I found it when looking at checkmember-related issues it was easy to handle it. I also use this opportunity to refactor and add comments to analyze_var().

@github-actions
Copy link
Contributor

github-actions bot commented Apr 1, 2025

Diff from mypy_primer, showing the effect of this PR on open source code:

spark (https://github.com/apache/spark)
+ python/pyspark/util.py:545: error: Unused "type: ignore[union-attr]" comment  [unused-ignore]
+ python/pyspark/util.py:584: error: Unused "type: ignore[union-attr]" comment  [unused-ignore]

@ilevkivskyi ilevkivskyi merged commit 715b982 into python:master Apr 1, 2025
18 checks passed
@ilevkivskyi ilevkivskyi deleted the classvar-union-bind-self branch April 1, 2025 17:06
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