tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

exceptions.py (1977B)


      1 # SPDX-License-Identifier: MIT
      2 
      3 from __future__ import annotations
      4 
      5 from typing import ClassVar
      6 
      7 
      8 class FrozenError(AttributeError):
      9    """
     10    A frozen/immutable instance or attribute have been attempted to be
     11    modified.
     12 
     13    It mirrors the behavior of ``namedtuples`` by using the same error message
     14    and subclassing `AttributeError`.
     15 
     16    .. versionadded:: 20.1.0
     17    """
     18 
     19    msg = "can't set attribute"
     20    args: ClassVar[tuple[str]] = [msg]
     21 
     22 
     23 class FrozenInstanceError(FrozenError):
     24    """
     25    A frozen instance has been attempted to be modified.
     26 
     27    .. versionadded:: 16.1.0
     28    """
     29 
     30 
     31 class FrozenAttributeError(FrozenError):
     32    """
     33    A frozen attribute has been attempted to be modified.
     34 
     35    .. versionadded:: 20.1.0
     36    """
     37 
     38 
     39 class AttrsAttributeNotFoundError(ValueError):
     40    """
     41    An *attrs* function couldn't find an attribute that the user asked for.
     42 
     43    .. versionadded:: 16.2.0
     44    """
     45 
     46 
     47 class NotAnAttrsClassError(ValueError):
     48    """
     49    A non-*attrs* class has been passed into an *attrs* function.
     50 
     51    .. versionadded:: 16.2.0
     52    """
     53 
     54 
     55 class DefaultAlreadySetError(RuntimeError):
     56    """
     57    A default has been set when defining the field and is attempted to be reset
     58    using the decorator.
     59 
     60    .. versionadded:: 17.1.0
     61    """
     62 
     63 
     64 class UnannotatedAttributeError(RuntimeError):
     65    """
     66    A class with ``auto_attribs=True`` has a field without a type annotation.
     67 
     68    .. versionadded:: 17.3.0
     69    """
     70 
     71 
     72 class PythonTooOldError(RuntimeError):
     73    """
     74    It was attempted to use an *attrs* feature that requires a newer Python
     75    version.
     76 
     77    .. versionadded:: 18.2.0
     78    """
     79 
     80 
     81 class NotCallableError(TypeError):
     82    """
     83    A field requiring a callable has been set with a value that is not
     84    callable.
     85 
     86    .. versionadded:: 19.2.0
     87    """
     88 
     89    def __init__(self, msg, value):
     90        super(TypeError, self).__init__(msg, value)
     91        self.msg = msg
     92        self.value = value
     93 
     94    def __str__(self):
     95        return str(self.msg)