python / python/cpython

ParamSpec(bound=None) incorrectly sets __bound__ to NoneType

Open
#142,750 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-typing type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

When creating a ParamSpec with bound=None, the runtime bound attribute is set to <class 'NoneType'> instead of None.

How to reproduce
from typing import ParamSpec, Callable

P1 = ParamSpec("P")
P2 = ParamSpec("P", bound=None)
P3 = ParamSpec("P", bound=Callable[[int, str], float])

def check_bound(label, p, expected):
    got = p.__bound__
    ok = (got is expected)
    exp_s = repr(expected)
    got_s = repr(got)
    print(f"{label}.__bound__ should be {exp_s}, got {got_s}  ->  {'OK' if ok else 'FAIL'}")

check_bound("P1", P1, None)
check_bound("P2", P2, None)
check_bound("P3", P3, Callable[[int, str], float])
Current behavior
d:\MyCode\cpython\PCbuild\amd64>python_d.exe py_bound.py
P1.__bound__ should be None, got <class 'NoneType'>  ->  FAIL
P2.__bound__ should be None, got <class 'NoneType'>  ->  FAIL
P3.__bound__ should be typing.Callable[[int, str], float], got typing.Callable[[int, str], float]  ->  OK
CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs
  • gh-142751

Contributor guide

Open the contributing guide

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.

Research direction

Start with the ParamSpec implementation and run the supplied reproduction on CPython main. Verify that an unbound ParamSpec and one created with bound=None expose bound as None, while an explicitly bounded ParamSpec retains its bound; the issue links PR gh-142751, so review that work first.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.