Useless lines affect type checking
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
**Versions**
Pylance: 2025.10.4
Pyright: 1.1.407
**Use case**
I want to to export my dataclass instances to CSV. Hence, I write with the following code snippet in VSCode.
```python
# Animals 1
import csv
from dataclasses import asdict, dataclass, fields
import sys
@dataclass
class Animal:
name: str
age: int
animals = [
Animal(name="Foo", age=3),
Animal(name="Bar", age=5),
]
field_names = [field.name for field in fields(Animal)]
writer = csv.DictWriter(sys.stdout, fieldnames=field_names)
writer.writeheader()
writer.writerows(
map(asdict, animals),
)
```
Python runs it as expected and all function signatures are correctly detected by Pylance.
**Expected behavior**
There should be no error.
**Current behavior**
I get 3 errors at line 22, on `map(asdict, animals)`.
```
Argument of type "Overload[(obj: DataclassInstance) -> dict[str, Any], (obj: DataclassInstance, *, dict_factory: (list[tuple[str, Any]]) -> _T@asdict) -> _T@asdict]" cannot be assigned to parameter "func" of type "(_T1@__new__) -> _S@map" in function "__new__"
No overloaded function matches type "(Animal) -> _S@map" (reportArgumentType)
Argument of type "Overload[(obj: DataclassInstance) -> dict[str, Any], (obj: DataclassInstance, *, dict_factory: (list[tuple[str, Any]]) -> _T@asdict) -> _T@asdict]" cannot be assigned to parameter "func" of type "(_T1@__new__) -> _S@map" in function "__new__"
No overloaded function matches type "(_T1@__new__) -> _S@map" (reportArgumentType)
Argument of type "map[Unknown]" cannot be assigned to parameter "rowdicts" of type "Iterable[Mapping[str, Any]]" in function "writerows"
"map[Unknown]" is incompatible with protocol "Iterable[Mapping[str, Any]]"
"__iter__" is an incompatible type
Type "() -> map[Unknown]" is not assignable to type "() -> Iterator[_T_co@Iterable]"
Function return type "map[Unknown]" is incompatible with type "Iterator[_T_co@Iterable]"
"map[Unknown]" is incompatible with protocol "Iterator[_T_co@Iterable]" (reportArgumentType)
```
**Bug analysis**
I have tested the 6 following variants which are basically doing the same things. Pylance and Pyright behave exactly the same, I only get errors in versions 1 and 4. The example I give uses `csv` and `dataclasses` but the issue seems much deeper since *useless lines affect type checking*.
- [Animals 1](https://pyright-play.net/?pyrightVersion=1.1.407&pythonVersion=3.14&locale=en&code=MQAgggdglgtghgGwM4gIwCh2wA4HsBOALiAMZIBu6AZvrjCACZyFwkJxJICmKOBxHBlBKEANI2at2ncVShcEDJFhh4iIJAE9lmAAJMWbDsqOdw0eAgBc6EHZAQ4MLlY2F8t%2B3ADmLkFAhCTDgLRBQAXhAAbU87SFhEAApHZ3CAIgAxXFw08R8ucIBmAEpRWPMEhGSnArSAITh8XJB88IBWUvQAXUw5BQYAfRSeEEiovsUAOmGQKgJZ%2BUV-CAX%2BpET4y2KegHd8KEIufFHSCkmAEWFCAHV9w-xErSRJpEIGXABXMVXFYaRwiaDP7FdB7A5HSZgw4ACy4cAYR0SIKhEJRtB263K8GwiUEVzyoWQnRBQA)
- [Animals 2](https://pyright-play.net/?pyrightVersion=1.1.407&code=MQAgggdglgtghgGwM4gEwCh2wA4HsBOALiAMZIBu6AZvrjCACZyFwkJxJICmKOBxHBlBKEANI2at2nLDDxEQSAJ5JM6AAJMWbDqp2dw0eAgBc6EBZAQ4MLicWF85y3ADmdkFAiFMcI4hQAXhAAbWcLSFhEAAprW0CAIgAxXFwE8TcuQIBmAEpRcMMohFibLISAITh8dJBMwIBWfPQAXUwqKC4EBgB9OJ4QYJCE-tqEzIS2gHd8KEIufEHSCgA6ABFhQgB1Wfn8aOUkFaRCBlwAVzEQDq6GfqRAm%2B6%2BsqRc9Bm5hZXP%2BYALLhwBgLaLvX7fcG0KZIaKFeDYaKCTYZfzIZrvIA)
- [Animals 3](https://pyright-play.net/?pyrightVersion=1.1.407&code=MQAgggdglgtghgGwM4gMwCh2wA4HsBOALiAMZIBu6AZvrjCACZyFwkJxJICmKOBxHBlBKEANI2at2nLDDxEQSAJ5JM6AAJMWbDqp2dw0eAgBc6EBZAQ4MLicWF85y3ADmdkFAiFMcI4hQAXhAAbWcLSFhEAAprW0CAIgAxXFwE8TcuQNQASlFwwyiEWJsshIAhOHx0kEzAgFY89ABdTAB3fChCLnwQYLJyADoAEWFCAHVO7vxo5SRBpEIGXABXMRAqKC4EBjieQJCEvZqEzITmnPQOrp7B6%2B6ACy44Bh7oy-vbz9o2pGiC%2BDYaKCMYZfzIJqXIA)
- [Animals 4](https://pyright-play.net/?pyrightVersion=1.1.407&code=MQAgggdglgtghgGwM4gCwCh2wA4HsBOALiAMZIBu6AZvrjCACZyFwkJxJICmKOBxHBlBKEANI2at2ncVShcEDJFhh4iIJAE9lmAAJMWbDsqOdw0eAgBc6EHZAQ4MLlY2F8t%2B3ADmLkFAhCTDgLRBQAXhAAbU87SFhEAApHZ3CAIgAxXFw08R8ucIBmAEpRWPMEhGSnArSAITh8XJB88IBWUvQAXUw5BQYAfRSeEEiovsUAOmGQKgJZ%2BUV-CAX%2BpET4y2KegHd8KEIufFHSCkmAEWFCAHV9w-xErSRJpEIGXABXMVXFYaRwqJpYbNNL5NJdYroPYHI6TaGHAAWXDgDCOiUh8NhmNoO3W5Xg2ESgiueVCyE6kKAA)
- [Animals 5](https://pyright-play.net/?pyrightVersion=1.1.407&code=MQAgggdglgtghgGwM4gKwCh2wA4HsBOALiAMZIBu6AZvrjCACZyFwkJxJICmKOBxHBlBKEANI2at2ncVShcEDJFhh4iIJAE9lmAAJMWbDsqOdw0eAgBc6EHZAQ4MLlY2F8t%2B3ADmLkFAhCTDgLRBQAXhAAbU87SFhEAApHZ3CAIgAxXFw08R8ucIBmAEpRWPMEhGSnArSAITh8XJB88NRS9ABdTFoAdwiQeGxEwWExFtDkYsw5BQYAfRSeEEio2cUAOiWQKgId%2BUV-CH25pET4y2Lu3vwoQi58FdIKDYARMYB1W-v8RK0kDZIQgMXAAV3G6wYSyQ4UhixqSGmNzuDw2yPuAAsuHAGA9Ekjvqj0Q9cP1EuU%2BkgytMgA)
- [Animals 6](https://pyright-play.net/?pyrightVersion=1.1.407&code=MQAgggdglgtghgGwM4gGwCh2wA4HsBOALiAMZIBu6AZvrjCACZyFwkJxJICmKOBxHBlBKEANI2at2ncVShcEDJFhh4iIJAE9lmAAJMWbDsqOdw0eAgBc6EHZAQ4MLlY2F8t%2B3ADmLkFAhCTDgLRBQAXhAAbU87SFhEAApHZ3CAIgAxXFw08R8ucIBmAEpRWPMEhGSnArSAITh8XJB88IBWUvQAXUxaAHcIkHhsRMFhMRbQ5GLMOQUGAH0UnhBIqLnFADplkCoCXflFfwgD%2BaRE%2BMtinr78KEIufFXSCk2AEXGAdTuH-EStJCbJCEBi4ACuEw2DGWSHCUKWNSQM1u90emxRDwAFlw4AxHolkT80RjHrgBolysNRkghCI8lMkWUZkA)
Contributor guide
Research direction
Reproduce the diagnostic with the provided Animals 1 example in the Pyright playground, focusing on map(asdict, animals) and comparing the six linked variants. Trace the type-checking path for overloaded dataclass asdict calls and map inference; done means the valid example produces no errors without regressing the other variants.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100