misc_py39
Testing features that either are 3.9+ only or render slightly different on 3.9.
1""" 2Testing features that either are 3.9+ only or render slightly different on 3.9. 3""" 4 5from __future__ import annotations 6 7from ctypes import Structure 8from dataclasses import dataclass 9import functools 10from typing import Union 11 12 13class SingleDispatchMethodExample: 14 @functools.singledispatchmethod 15 def fancymethod(self, str_or_int: Union[str, int]): 16 """A fancy method which is capable of handling either `str` or `int`. 17 18 :param str_or_int: string or integer to handle 19 """ 20 raise NotImplementedError(f"{type(str_or_int)=} not implemented!") 21 22 @fancymethod.register 23 def fancymethod_handle_str(self, str_to_handle: str): 24 """Fancy method handles a string. 25 26 :param str_to_handle: string which will be handled 27 """ 28 print(f"{type(str_to_handle)} = '{str_to_handle}") 29 30 @fancymethod.register 31 def _fancymethod_handle_int(self, int_to_handle: int): 32 """Fancy method handles int (not shown in doc). 33 34 :param int_to_handle: int which will be handled 35 """ 36 print(f"{type(int_to_handle)} = '{int_to_handle:x}'") 37 38 39@dataclass(init=False) 40class DataclassStructure(Structure): 41 """DataclassStructure raises for `inspect.signature`."""
class
SingleDispatchMethodExample:
14class SingleDispatchMethodExample: 15 @functools.singledispatchmethod 16 def fancymethod(self, str_or_int: Union[str, int]): 17 """A fancy method which is capable of handling either `str` or `int`. 18 19 :param str_or_int: string or integer to handle 20 """ 21 raise NotImplementedError(f"{type(str_or_int)=} not implemented!") 22 23 @fancymethod.register 24 def fancymethod_handle_str(self, str_to_handle: str): 25 """Fancy method handles a string. 26 27 :param str_to_handle: string which will be handled 28 """ 29 print(f"{type(str_to_handle)} = '{str_to_handle}") 30 31 @fancymethod.register 32 def _fancymethod_handle_int(self, int_to_handle: int): 33 """Fancy method handles int (not shown in doc). 34 35 :param int_to_handle: int which will be handled 36 """ 37 print(f"{type(int_to_handle)} = '{int_to_handle:x}'")
@functools.singledispatchmethod
def
fancymethod(self, str_or_int: Union[str, int]):
15 @functools.singledispatchmethod 16 def fancymethod(self, str_or_int: Union[str, int]): 17 """A fancy method which is capable of handling either `str` or `int`. 18 19 :param str_or_int: string or integer to handle 20 """ 21 raise NotImplementedError(f"{type(str_or_int)=} not implemented!")
A fancy method which is capable of handling either str
or int
.
Parameters
- str_or_int: string or integer to handle
@fancymethod.register
def
fancymethod_handle_str(self, str_to_handle: str):
23 @fancymethod.register 24 def fancymethod_handle_str(self, str_to_handle: str): 25 """Fancy method handles a string. 26 27 :param str_to_handle: string which will be handled 28 """ 29 print(f"{type(str_to_handle)} = '{str_to_handle}")
Fancy method handles a string.
Parameters
- str_to_handle: string which will be handled
@dataclass(init=False)
class
DataclassStructure40@dataclass(init=False) 41class DataclassStructure(Structure): 42 """DataclassStructure raises for `inspect.signature`."""
DataclassStructure raises for inspect.signature
.
Inherited Members
- _ctypes.Structure
- Structure