typing

Correct Type annotation for __init__

久未见 提交于 2021-01-20 18:49:10
问题 What is the correct type annotation for a __init__ function in python? class MyClass: ... Which of the following would make more sense? def __init__(self): # type: (None) -> None def __init__(self): # type: (MyClass) -> MyClass def __init__(self): # type: (None) -> MyClass Since we would normally instantiate as myclass = MyClass() , but the __init__ function itself has no return value. 回答1: self should be omitted from the annotation when it is given as a comment, and __init__() should be

Correct Type annotation for __init__

橙三吉。 提交于 2021-01-20 18:49:05
问题 What is the correct type annotation for a __init__ function in python? class MyClass: ... Which of the following would make more sense? def __init__(self): # type: (None) -> None def __init__(self): # type: (MyClass) -> MyClass def __init__(self): # type: (None) -> MyClass Since we would normally instantiate as myclass = MyClass() , but the __init__ function itself has no return value. 回答1: self should be omitted from the annotation when it is given as a comment, and __init__() should be

How to create 2 incompatible number-like types in TypeScript?

南楼画角 提交于 2020-12-25 02:03:31
问题 I've been trying to figure out how to create 2 mutually-incompatible number-like/integer types in TS. For example, in the code below, height and weight are both number-like, but the concept of adding them together or treating them equivalently is nonsensical and should be an error. type height = number; // inches type weight = number; // pounds var a: height = 68; var b: weight = operateScale(); // Call to external, non-TS function, which returns a weight. console.log(a+b); // Should be an

How to create 2 incompatible number-like types in TypeScript?

别等时光非礼了梦想. 提交于 2020-12-25 02:02:31
问题 I've been trying to figure out how to create 2 mutually-incompatible number-like/integer types in TS. For example, in the code below, height and weight are both number-like, but the concept of adding them together or treating them equivalently is nonsensical and should be an error. type height = number; // inches type weight = number; // pounds var a: height = 68; var b: weight = operateScale(); // Call to external, non-TS function, which returns a weight. console.log(a+b); // Should be an

How to create 2 incompatible number-like types in TypeScript?

寵の児 提交于 2020-12-25 02:01:50
问题 I've been trying to figure out how to create 2 mutually-incompatible number-like/integer types in TS. For example, in the code below, height and weight are both number-like, but the concept of adding them together or treating them equivalently is nonsensical and should be an error. type height = number; // inches type weight = number; // pounds var a: height = 68; var b: weight = operateScale(); // Call to external, non-TS function, which returns a weight. console.log(a+b); // Should be an

How to create 2 incompatible number-like types in TypeScript?

若如初见. 提交于 2020-12-25 02:01:29
问题 I've been trying to figure out how to create 2 mutually-incompatible number-like/integer types in TS. For example, in the code below, height and weight are both number-like, but the concept of adding them together or treating them equivalently is nonsensical and should be an error. type height = number; // inches type weight = number; // pounds var a: height = 68; var b: weight = operateScale(); // Call to external, non-TS function, which returns a weight. console.log(a+b); // Should be an