error in set unions
Open
Nobody has claimed this yet.
bug
topic-type-context
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
In the following file, mypy (version 0.950) reports (correctly) ok function as ok, but raises an error (error: Argument 1 to "union" of "set" has incompatible type "Set[str]"; expected "Set[Optional[str]]") in error function.
from typing import Set
from zoneinfo import available_timezones
x = {"UTC"}
def error() -> Set[str]:
return available_timezones() - set.union(x)
def ok() -> Set[str]:
a, b = available_timezones(), set.union(x)
return a - b
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with mypy 0.950 using the two functions shown in the report, comparing the direct expression with the intermediate variables. Trace the set-union type-checking path and add a regression test covering both forms; done means the valid error function no longer produces the incompatible-argument diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100