python / python/cpython

Argument Clinic: move converters defined in several files to libclinic

Aberta
#156,261 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

extension-modules topic-argument-clinic type-refactor
Linguagem predominante
Python
Estrelas
77.2k
Forks
35.9k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

Several custom converters are defined in more than one C file:

  • pid_t — in posixmodule.c, _posixsubprocess.c and resource.c.
  • Py_off_t — in posixmodule.c and _ssl.c; the Py_off_t type and the converter function are duplicated as well, and _io has yet another copy of the type.
  • HANDLE — in _multiprocessing/multiprocessing.c, overlapped.c, msvcrtmodule.c, _testconsole.c and _winapi.c.
  • DWORD — in overlapped.c, winreg.c and _winapi.c.
  • BOOL — in overlapped.c and _winapi.c.

The copies are not always equivalent: two of the pid_t converters compare the result with -1 instead of (pid_t)-1, and DWORD in _winapi.c uses the format unit "k", which accepts negative values, while in other modules it rejects them.

The registry of converters is global, so the definition in the file which is processed first can be used in other files. The generated code therefore depends on the order of processing — removing the definition of HANDLE from one module silently changes the code generated for others.

Other converters are defined only in posixmodule.c, although the corresponding C functions are already shared, so other modules convert the argument in the "impl" function instead of declaring its type:

  • uid_t and gid_t_Py_Uid_Converter() and _Py_Gid_Converter() are declared in posixmodule.h and are called by hand in pwd.getpwuid(), grp.getgrgid() and _posixsubprocess.fork_exec().

There is no converter for time_t at all: time.gmtime(), time.localtime() and time.ctime() parse their argument with a hand-written helper, and _datetime calls _PyTime_ObjectToTime_t() directly.

I am going to move these converters to Tools/clinic/libclinic/converters.py.

Linked PRs
  • gh-156262
  • gh-156294

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece em Tools/clinic/libclinic/converters.py e, em seguida, inspecione as definições dos converters e as declarações compartilhadas em posixmodule.c, _posixsubprocess.c, resource.c, _ssl.c, _io e nos módulos do Windows listados na issue. Verifique como o Argument Clinic processa os módulos e compare o código gerado; a tarefa estará concluída quando os converters estiverem centralizados sem alterar os valores aceitos ou o comportamento gerado.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
c, python
Domínio
build-system, tooling
Tipo de issue
Refatoração
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Claramente especificada
Facilidade para iniciantes
25/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.