@@ -55,8 +55,20 @@ def _get_class_for_interface(interface: str) -> Type[BusABC]:
5555 return cast (Type [BusABC ], bus_class )
5656
5757
58- class Bus (BusABC ): # pylint: disable=abstract-method
59- """Bus wrapper with configuration loading.
58+ @util .deprecated_args_alias (
59+ deprecation_start = "4.2.0" ,
60+ deprecation_end = "5.0.0" ,
61+ bustype = "interface" ,
62+ context = "config_context" ,
63+ )
64+ def Bus (
65+ channel : Optional [Channel ] = None ,
66+ interface : Optional [str ] = None ,
67+ config_context : Optional [str ] = None ,
68+ ignore_config : bool = False ,
69+ ** kwargs : Any ,
70+ ) -> BusABC :
71+ """Create a new bus instance with configuration loading.
6072
6173 Instantiates a CAN Bus of the given ``interface``, falls back to reading a
6274 configuration file from default locations.
@@ -99,45 +111,30 @@ class Bus(BusABC): # pylint: disable=abstract-method
99111 if the ``channel`` could not be determined
100112 """
101113
102- @staticmethod
103- @util .deprecated_args_alias (
104- deprecation_start = "4.2.0" ,
105- deprecation_end = "5.0.0" ,
106- bustype = "interface" ,
107- context = "config_context" ,
108- )
109- def __new__ ( # type: ignore
110- cls : Any ,
111- channel : Optional [Channel ] = None ,
112- interface : Optional [str ] = None ,
113- config_context : Optional [str ] = None ,
114- ignore_config : bool = False ,
115- ** kwargs : Any ,
116- ) -> BusABC :
117- # figure out the rest of the configuration; this might raise an error
118- if interface is not None :
119- kwargs ["interface" ] = interface
120- if channel is not None :
121- kwargs ["channel" ] = channel
122-
123- if not ignore_config :
124- kwargs = util .load_config (config = kwargs , context = config_context )
125-
126- # resolve the bus class to use for that interface
127- cls = _get_class_for_interface (kwargs ["interface" ])
128-
129- # remove the "interface" key, so it doesn't get passed to the backend
130- del kwargs ["interface" ]
131-
132- # make sure the bus can handle this config format
133- channel = kwargs .pop ("channel" , channel )
134- if channel is None :
135- # Use the default channel for the backend
136- bus = cls (** kwargs )
137- else :
138- bus = cls (channel , ** kwargs )
114+ # figure out the rest of the configuration; this might raise an error
115+ if interface is not None :
116+ kwargs ["interface" ] = interface
117+ if channel is not None :
118+ kwargs ["channel" ] = channel
119+
120+ if not ignore_config :
121+ kwargs = util .load_config (config = kwargs , context = config_context )
122+
123+ # resolve the bus class to use for that interface
124+ cls = _get_class_for_interface (kwargs ["interface" ])
125+
126+ # remove the "interface" key, so it doesn't get passed to the backend
127+ del kwargs ["interface" ]
128+
129+ # make sure the bus can handle this config format
130+ channel = kwargs .pop ("channel" , channel )
131+ if channel is None :
132+ # Use the default channel for the backend
133+ bus = cls (** kwargs )
134+ else :
135+ bus = cls (channel , ** kwargs )
139136
140- return cast ( BusABC , bus )
137+ return bus
141138
142139
143140def detect_available_configs (
@@ -146,7 +143,7 @@ def detect_available_configs(
146143 """Detect all configurations/channels that the interfaces could
147144 currently connect with.
148145
149- This might be quite time consuming.
146+ This might be quite time- consuming.
150147
151148 Automated configuration detection may not be implemented by
152149 every interface on every platform. This method will not raise
0 commit comments