Python typing.SupportsFloat() Examples
The following are 8
code examples of typing.SupportsFloat().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
typing
, or try the search function
.
Example #1
Source File: type_inference_visitor.py From pyta with GNU General Public License v3.0 | 6 votes |
def _arithm_convert(self, node: NodeNG, method: str, t1: type, t2: type) -> Optional[TypeInfo]: if t1 is complex and t2 is complex: common_type = complex elif ((t1 is complex and issubclass(t2, typing.SupportsFloat)) or (t2 is complex and issubclass(t1, typing.SupportsFloat))): # TODO: handle complex better. Looks like int, float don't # support typing.SupportsComplex. common_type = complex elif ((t1 is float and issubclass(t2, typing.SupportsFloat)) or (t2 is float and issubclass(t1, typing.SupportsFloat))): common_type = float else: common_type = None if common_type: return self._handle_call(node, method, common_type, common_type) else: return None
Example #2
Source File: test_typing.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_supports_float(self): assert issubclass(float, typing.SupportsFloat) assert not issubclass(str, typing.SupportsFloat)
Example #3
Source File: operation.py From pyfuzzylite with GNU Affero General Public License v3.0 | 5 votes |
def scalar(x: Union[SupportsFloat, str, bytes]) -> float: from . import lib return lib.floating_point(x)
Example #4
Source File: library.py From pyfuzzylite with GNU Affero General Public License v3.0 | 5 votes |
def floating_point(self, value: Union[SupportsFloat, str, bytes]) -> float: return self.floating_point_type(value)
Example #5
Source File: test_typing.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_supports_float(self): self.assertIsSubclass(float, typing.SupportsFloat) self.assertNotIsSubclass(str, typing.SupportsFloat)
Example #6
Source File: utilities.py From maildown with MIT License | 5 votes |
def write_config(**config: Dict[str, Union[str, SupportsFloat, bool]]) -> None: """ Updates the existing local config with the given additional arguments ### Parameters: - `config`: the new configuration items to add to the configuration """ existing = get_config() for key, val in config.items(): existing[key] = val with open(os.path.expanduser("~/maildown.toml"), "w") as f: f.write(toml.dumps(config))
Example #7
Source File: ch03_ex4.py From Mastering-Object-Oriented-Python-Second-Edition with MIT License | 5 votes |
def __new__(cls: Type, value: SupportsFloat, unit: str) -> 'Float_Units_Ugly': obj = cast('Float_Units_Ugly', cast(type, super()).__new__(cls, float(value))) obj.unit = unit return obj
Example #8
Source File: ch03_ex5.py From Mastering-Object-Oriented-Python-Second-Edition with MIT License | 5 votes |
def __new__(cls: Type, value: SupportsFloat, unit: str) -> "Float_Units_Ugly": # print(f"Float_Units_Ugly {cls}") obj = cast("Float_Units_Ugly", cast(type, super()).__new__(cls, float(value))) obj.unit = unit return obj