Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
Bug report
Bug description:
I tried to search for a related ticket by various queries but did not find any, hopefully I haven't overlooked it.
While rewriting a codebase fromOptional[foo] to the newerfoo | None style, I encountered thatthreading.Lock does not allow the latter.
Example on MacOS 3.12.1:
>>>fromtypingimportOptional>>>fromthreadingimportLock>>>Optional[Lock]typing.Optional[<built-infunctionallocate_lock>]>>>Lock|NoneTraceback (mostrecentcalllast):File"<stdin>",line1,in<module>TypeError:unsupportedoperandtype(s)for|:'builtin_function_or_method'and'NoneType'
Given that the documentation states the following, the error makes sense:
Note that Lock is actually a factory function which returns an instance of the most efficient version of the concrete Lock class that is supported by the platform.
I actually didn't know it was a factory function. I would not intentionally create a<function> | None type. But since the documentation describesthreading.Lock as a class, one would expect to be able to use it as any other type.
CPython versions tested on:
3.11, 3.12, 3.13.0a3
Operating systems tested on:
Linux, macOS