##// END OF EJS Templates
interfaces: make the `peer` mixin not a Protocol to fix Python 3.10 failures...
interfaces: make the `peer` mixin not a Protocol to fix Python 3.10 failures I can't find any documentation on this, but it appears that Protocol class attributes don't get inherited in subclasses that explicitly subclass a Protocol until Python 3.11, which caused a ton of failures in CI on macOS and Windows (which both test using Python 3.9). The problem started with 1df97507c6b8, and typically manifested as most tests failing to access `ui` on various `peer` classes. Here's a short proof of concept: from __future__ import annotations from typing import ( Protocol, ) class peer(Protocol): limitedarguments: bool = False def __init__(self, arg1, arg2, remotehidden: bool = False) -> None: self.arg1 = arg1 self.arg2 = arg2 class subclass(peer): def __init__(self, arg1, arg2): super(subclass, self).__init__(arg1, arg2, False) sub = subclass(1, 2) print("sub.arg1 is %r" % sub.arg1) When run with Python 3.8.10, 3.9.13, and 3.10.11, the result is: $ py -3.8 prot-test.py Traceback (most recent call last): File "prot-test.py", line 20, in <module> print("sub.arg1 is %r" % sub.arg1) AttributeError: 'subclass' object has no attribute 'arg1' On Python 3.11.9, 3.12.7, and 3.13.0, the result is: $ py -3.11 ../prot-test.py sub.arg1 is 1 Explicitly adding annotations to `peer` like `limitedarguments` didn't help.

File last commit:

r52756:f4733654 default
r53403:199b0e62 default
Show More
node.py
61 lines | 1.8 KiB | text/x-python | PythonLexer
# node.py - basic nodeid manipulation for mercurial
#
# Copyright 2005, 2006 Olivia Mackall <olivia@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import annotations
import binascii
# This ugly style has a noticeable effect in manifest parsing
hex = binascii.hexlify
bin = binascii.unhexlify
def short(node):
return hex(node[:6])
nullrev = -1
# pseudo identifier for working directory
# (experimental, so don't add too many dependencies on it)
wdirrev = 0x7FFFFFFF
class sha1nodeconstants:
nodelen = 20
# In hex, this is '0000000000000000000000000000000000000000'
nullid = b"\0" * nodelen
nullhex = hex(nullid)
# Phony node value to stand-in for new files in some uses of
# manifests.
# In hex, this is '2121212121212121212121212121212121212121'
newnodeid = b'!!!!!!!!!!!!!!!!!!!!'
# In hex, this is '3030303030303030303030303030306164646564'
addednodeid = b'000000000000000added'
# In hex, this is '3030303030303030303030306d6f646966696564'
modifiednodeid = b'000000000000modified'
wdirfilenodeids = {newnodeid, addednodeid, modifiednodeid}
# pseudo identifier for working directory
# (experimental, so don't add too many dependencies on it)
# In hex, this is 'ffffffffffffffffffffffffffffffffffffffff'
wdirid = b"\xff" * nodelen
wdirhex = hex(wdirid)
# legacy starting point for porting modules
nullid = sha1nodeconstants.nullid
nullhex = sha1nodeconstants.nullhex
newnodeid = sha1nodeconstants.newnodeid
addednodeid = sha1nodeconstants.addednodeid
modifiednodeid = sha1nodeconstants.modifiednodeid
wdirfilenodeids = sha1nodeconstants.wdirfilenodeids
wdirid = sha1nodeconstants.wdirid
wdirhex = sha1nodeconstants.wdirhex