polymorphic overloads on `list.__add__` and `dict.__or__` lead to divergences in type checkers.
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
Direção de pesquisa
Comece pelos overloads de list.add e dict.or e, em seguida, revise os PRs #14282 e #14284 para analisar a simplificação proposta. Reproduza os exemplos de list e dict com mypy e pyright e use mypy-primer para verificar se as alterações de stub escolhidas removem os erros divergentes do wrapper.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
The overloads on list.__add__ lead to divergent behavior between mypy and pyright when doing something as simple as a list concatenation
# Overloading looks unnecessary, but is needed to work around complex mypy problems
@overload
def __add__(self, value: list[_T], /) -> list[_T]: ...
@overload
def __add__(self, value: list[_S], /) -> list[_S | _T]: ...
Code sample in pyright playground, https://mypy-play.net/?mypy=latest&python=3.12&gist=abf6a8834020af17a16bd8cfb44b2f10
from typing import Any, overload
class ListA[T]: # emulates builtins list
@overload
def __add__(self, other: "ListA[T]", /) -> "ListA[T]": return ListA()
@overload
def __add__[S](self, other: "ListA[S]", /) -> "ListA[T | S]": return ListA()
class ListB[T]: # without overloads
def __add__[S](self, other: "ListB[S]", /) -> "ListB[T | S]": return ListB()
# mypy | pyright
reveal_type( list[str]() + list[str]() ) # list[str] | list[str] ✅️
reveal_type( list[str]() + list[int]() ) # list[str | int] | list[str | int] ✅️
reveal_type( list[str]() + list[Any]() ) # list[Any] | list[str] ❌️
reveal_type( ListA[str]() + ListA[str]() ) # ListA[str] | ListA[str] ✅️
reveal_type( ListA[str]() + ListA[int]() ) # ListA[str | int] | ListA[str | int] ✅️
reveal_type( ListA[str]() + ListA[Any]() ) # ListA[Any] | ListA[str] ❌️
reveal_type( ListB[str]() + ListB[str]() ) # ListB[str] | ListB[str] ✅️
reveal_type( ListB[str]() + ListB[int]() ) # ListB[str | int] | ListB[str | int] ✅️
reveal_type( ListB[str]() + ListB[Any]() ) # ListB[str | Any] | ListB[str | Any] ✅️
This ultimately causes some very annoying type errors when checking wrapper functions in pyright.
Code sample in pyright playground
from typing import Mapping, Any
# function with 2 optional arguments
def foo(arg: object, /, *, opt1: str = ..., opt2: int = ...) -> None: ...
# wrapper that forwards args via dict
def foo_wrapper(arg: object, foo_kwargs: Mapping[str, Any]) -> None:
# apply new defaults
foo_kwargs = {"opt1": "new_default"} | dict(foo_kwargs)
foo(arg, **foo_kwargs) # "str" cannot be assigned to parameter "opt2"
PR #14282 and #14284 show mypy-primer results of simplifying the overloads away from list.__add__ and dict.__or__.
- Linguagem predominante
- Python
- Estrelas
- 5.1k
- Forks
- 2.1k
- Merge médio
- 2d 1h
- PRs com merge (30d)
- 115
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de python/typeshed
-
`networkx.set_edge_attributes` should support scalar value + nameTalvez já em andamento @Fire162 assumiu há 10 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 67/100
Mantenedores costumam responder em até 1 dia
-
false alarm on decode callTalvez já em andamento @jw9829 assumiu há 38 dias. Abertahelp wanted stubs: false positive
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
python/typeshed#16441 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Don't run pyright basic checks on projects with strict pyright settings in CITalvez já em andamento @Mohith1612 assumiu há 74 dias. Abertaproject: infrastructure
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
python/typeshed#16005 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
stubs: improvement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
python/typeshed#15548 · 5 comentários ·
Mantenedores costumam responder em até 1 dia
-
stubs: improvement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 64/100
python/typeshed#15529 · 5 comentários ·
Mantenedores costumam responder em até 1 dia
Todas as issues de python/typeshed
Issues semelhantes
-
DBFS append mode silently overwrites existing filesTalvez já em andamento @IlyaKhalafi assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
fsspec/filesystem_spec#2429 ·
Mantenedores costumam responder em até 1 dia
-
[Bug]: Retrieval rerank fallback statistics stay zero after provider failureTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
volcengine/OpenViking#7014 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
fedora-copr/copr#4600 ·
Mantenedores costumam responder em até 2 dias
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
ansys/pydpf-core#3620 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia