mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Run enum.Enum analysis on non-assigned calls

Open A5rocks opened this issue 1 month ago • 3 comments

Fixes https://github.com/python/mypy/issues/20266

semanal_enum.py generally feels kinda strange, like process_enum_call feels redundant? The only thing it adds over simply making semanal do check_enum_call is... check that we aren't assigning to a property or a tuple. I feel like we could separate that and make it somewhat nicer.

I did the minimal thing though, so I did not refactor things.

A5rocks avatar Nov 20 '25 04:11 A5rocks

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

psycopg (https://github.com/psycopg/psycopg)
+ psycopg/psycopg/types/enum.py:175: error: Enum() expects a string literal as the first argument  [misc]

github-actions[bot] avatar Nov 20 '25 04:11 github-actions[bot]

I think that error is fine. It's not clear whether we should error or not, but e.g. I can imagine a world where the returned Enum has to match a protocol (e.g. "has attribute a"). That wouldn't work right now, but the error message as stated would be correct.

(maybe others have different opinions?)

A5rocks avatar Nov 20 '25 04:11 A5rocks

I think that error is fine. It's not clear whether we should error or not

I think the message could be worded a bit differently to clarify that this is a mypy limitation and not a runtime requirement, but the presence of this error is definitely fine - there should be some limits when we just say "nah, sorry, don't know what you mean here" and bail out

sterliakov avatar Nov 24 '25 11:11 sterliakov