mercurial/typelib.py
changeset 49793 8147abc05794
equal deleted inserted replaced
49783:e1953a34c110 49793:8147abc05794
       
     1 # typelib.py - type hint aliases and support
       
     2 #
       
     3 # Copyright 2022 Matt Harbison <matt_harbison@yahoo.com>
       
     4 #
       
     5 # This software may be used and distributed according to the terms of the
       
     6 # GNU General Public License version 2 or any later version.
       
     7 
       
     8 import typing
       
     9 
       
    10 # Note: this is slightly different from pycompat.TYPE_CHECKING, as using
       
    11 # pycompat causes the BinaryIO_Proxy type to be resolved to ``object`` when
       
    12 # used as the base class during a pytype run.
       
    13 TYPE_CHECKING = typing.TYPE_CHECKING
       
    14 
       
    15 
       
    16 # The BinaryIO class provides empty methods, which at runtime means that
       
    17 # ``__getattr__`` on the proxy classes won't get called for the methods that
       
    18 # should delegate to the internal object.  So to avoid runtime changes because
       
    19 # of the required typing inheritance, just use BinaryIO when typechecking, and
       
    20 # ``object`` otherwise.
       
    21 if TYPE_CHECKING:
       
    22     from typing import (
       
    23         BinaryIO,
       
    24     )
       
    25 
       
    26     BinaryIO_Proxy = BinaryIO
       
    27 else:
       
    28     BinaryIO_Proxy = object