mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
Merge pull request #4398 from mhils/pdoc
duplicate hooks: warn instead of raise
This commit is contained in:
commit
a92279e69f
@ -1,4 +1,5 @@
|
||||
import re
|
||||
import warnings
|
||||
from dataclasses import dataclass, is_dataclass, fields
|
||||
from typing import ClassVar, Any, Dict, Type, Set, List, TYPE_CHECKING, Sequence
|
||||
|
||||
@ -32,7 +33,7 @@ class Hook:
|
||||
cls.name = re.sub('(?!^)([A-Z]+)', r'_\1', name).lower()
|
||||
if cls.name in all_hooks:
|
||||
other = all_hooks[cls.name]
|
||||
raise RuntimeError(f"Two conflicting event classes for {cls.name}: {cls} and {other}")
|
||||
warnings.warn(f"Two conflicting event classes for {cls.name}: {cls} and {other}", RuntimeWarning)
|
||||
if cls.name == "":
|
||||
return # don't register Hook class.
|
||||
all_hooks[cls.name] = cls
|
||||
|
@ -4,6 +4,7 @@ from abc import ABCMeta
|
||||
from enum import Flag
|
||||
from typing import List, Literal, Optional, Sequence, Tuple, Union, TYPE_CHECKING
|
||||
|
||||
import mitmproxy
|
||||
from mitmproxy import certs
|
||||
from mitmproxy.coretypes import serializable
|
||||
from mitmproxy.net import server_spec
|
||||
|
@ -5,6 +5,7 @@ The counterpart to events are commands.
|
||||
"""
|
||||
import socket
|
||||
import typing
|
||||
import warnings
|
||||
from dataclasses import dataclass, is_dataclass
|
||||
|
||||
from mitmproxy.proxy import commands
|
||||
@ -78,7 +79,7 @@ class CommandCompleted(Event):
|
||||
raise RuntimeError(f"{command_cls} needs a properly annotated command attribute.")
|
||||
if command_cls in command_reply_subclasses:
|
||||
other = command_reply_subclasses[command_cls]
|
||||
raise RuntimeError(f"Two conflicting subclasses for {command_cls}: {cls} and {other}")
|
||||
warnings.warn(f"Two conflicting subclasses for {command_cls}: {cls} and {other}", RuntimeWarning)
|
||||
command_reply_subclasses[command_cls] = cls
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -31,6 +31,6 @@ def test_command_completed():
|
||||
class FooCompleted1(events.CommandCompleted):
|
||||
command: FooCommand
|
||||
|
||||
with pytest.raises(RuntimeError, match="conflicting subclasses"):
|
||||
with pytest.warns(RuntimeWarning, match="conflicting subclasses"):
|
||||
class FooCompleted2(events.CommandCompleted):
|
||||
command: FooCommand
|
||||
|
@ -24,7 +24,7 @@ def test_hook():
|
||||
assert e.args() == [b"foo"]
|
||||
assert FooHook in hooks.all_hooks.values()
|
||||
|
||||
with pytest.raises(RuntimeError, match="Two conflicting event classes"):
|
||||
with pytest.warns(RuntimeWarning, match="Two conflicting event classes"):
|
||||
@dataclass
|
||||
class FooHook2(hooks.Hook):
|
||||
name = "foo"
|
||||
|
Loading…
Reference in New Issue
Block a user