stubgen creates duplicate class definitions
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 35/100
Direção de pesquisa
Comece com stubgen e seu tratamento das definições condicionais de plataforma em serialposix; o arquivo gerado stubs/serial/serialposix.pyi mostra as declarações duplicadas de PlatformSpecific. Determine como as definições de classes específicas da plataforma devem ser representadas e, em seguida, verifique se o stub gerado não produz mais nomes duplicados e se o mypy o aceita em todas as plataformas.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
I need a stub for the serial package, and attempted to use stubgen to create it. The problem arises in the serialposix subpackage, which defines the PlatformSpecific class differently depending upon the platform it's running on. When stubgen processes this code, it discards all the conditional pieces, the end result being multiple definitions of the PlatformSpecific class, which, not surprisingly, mypy is very unhappy about.
Here's what the original code looks like (trimmed for compactness):
plat = sys.platform.lower()
if plat[:5] == 'linux': # Linux (confirmed) # noqa
class PlatformSpecific(PlatformSpecificBase):
…
elif plat == 'cygwin': # cygwin/win32 (confirmed)
class PlatformSpecific(PlatformSpecificBase):
…
elif plat[:6] == 'darwin': # OS X
class PlatformSpecific(PlatformSpecificBase):
…
and so on. You get the picture.
Running mypy after generating the stub gives:
stubs/serial/serialposix.pyi:24: error: Name 'PlatformSpecific' already defined on line 20 stubs/serial/serialposix.pyi:29: error: Name 'PlatformSpecific' already defined on line 20 stubs/serial/serialposix.pyi:37: error: Name 'PlatformSpecific' already defined on line 20 stubs/serial/serialposix.pyi:42: error: Name 'PlatformSpecific' already defined on line 20
Now, I can manually go in and edit the generated stub, commenting out the class definitions for platforms other than the one I am running on. But the problem is that I can't then check in that stub and expect mypy to run correctly on other platforms.
I don't think this is a typeshed issue, because I don't see a way that the stub can be written to work across platforms, which seems to be a problem inherent in the way that stubgen, and stubs in general, work. Unless I'm missing something (which is entirely possible), there is nothing in mypy that will allow this type of code to be stubbed successfully.
- Linguagem predominante
- Python
- Estrelas
- 20.6k
- Forks
- 3.3k
- Merge médio
- 1d 18h
- PRs com merge (30d)
- 54
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/mypy
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
-
documentation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
-
bug topic-configuration topic-error-reporting
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Todas as issues de python/mypy
Issues semelhantes
-
area/auth bug comp/agent P3 platform/discord type/security
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
NousResearch/hermes-agent#117848 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
bancolombia/sentinel#23 ·
-
test md AbertaCI
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100