X Tutup
The Wayback Machine - https://web.archive.org/web/20250528212155/https://github.com/python/cpython/issues/94077
Skip to content

Subclassing threading Lock/RLock: better Exception messages #94077

Open
@jamesbraza

Description

@jamesbraza

Bug report

Please see the below minimal repro:

from threading import Lock, RLock

class SubclassLock(Lock):
    pass

class SubclassRLock(RLock):
    pass

The subclass of Lock emits:

Traceback (most recent call last):
  File "/path/to/file.py", line 3, in <module>
    class SubclassLock(Lock):
TypeError: cannot create 'builtin_function_or_method' instances

The subclass of RLock emits:

Traceback (most recent call last):
  File "/path/to/file.py", line 6, in <module>
    class SubclassRLock(RLock):
TypeError: function() argument 'code' must be code, not str

Both of these messages are relatively cryptic. I think if Python doesn't support subclassing Lock/RLock, it should be documented in threading, and this error message should be more friendly/clear.

Your environment

  • CPython versions tested on: 3.10.3
  • Operating system and architecture: macOS Big Sur 11.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup