Spec and conformance tests disagree on converting constructors into callable for classes with `__new__` and `__init__`

Open
#2,158 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Compare the constructor behavior described in docs/spec/constructors.rst around the linked section with the case in conformance/tests/constructors_callable.py. Determine which callable type is intended for a class defining both new and init, then align the specification and conformance test and run the relevant constructor conformance checks.

Written by the indexing model from the issue text.

Description

topic: conformance tests topic: typing spec

For classes with both __new__ and __init__, when converting the constructor into a Callable, the spec says that

https://github.com/python/typing/blame/20096eeba502b1bf955fcf62b389adbaa63fc61b/docs/spec/constructors.rst#L457

    class B:
        """ __new__ and __init__ """
        def __new__(cls, *args, **kwargs) -> Self:
            ...

        def __init__(self, x: int) -> None:
            ...

    reveal_type(accepts_callable(B))  # ``def (*args, **kwargs) -> B | def (x: int) -> B``

The conformance test says that

https://github.com/python/typing/blob/20096eeba502b1bf955fcf62b389adbaa63fc61b/conformance/tests/constructors_callable.py#L54-L64

Dominant language
Python
Stars
1.8k
Forks
302
Avg merge
23h
Merged PRs (30d)
8

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python/typing

All issues in python/typing

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.