typing

TypeScript type definition; export default for using external JavaScript library in Angular2

前提是你 提交于 2019-12-11 13:17:47
问题 I'm trying to integrate a JavaScript library (bricks.js) that has no publicly available type definition. Basically, what the library is exporting is something like this: export default (config) => { const instance = SomeConstructorFunction(config); return instance; } I cannot figure out how to correctly create a type definition ( .d.ts ) for this function; either tsc compiles when I import, I get undefined or tsc won't compile. For this instance .d.ts compiles: declare module 'bricks.js' {

How to make mypy complain about assigning an Any to an int (part 2)

不羁的心 提交于 2019-12-11 08:13:32
问题 (This is a follow-up to this question.) My code base is fully statically typed (annotation) but at some points there is the Any type, for example because a value was parsed from a JSON string. Here is my minimal example: import json from typing import Any, Dict, Union def main() -> None: data = json.loads('{"value" = "three"}') my_int: int = data['value'] if __name__ == "__main__": main() mypy --strict accepts this code. However I would like to find these places automatically, to take the

How to make mypy complain about assigning an Any to an int

独自空忆成欢 提交于 2019-12-11 06:36:51
问题 mypy --strict dutifully complains about the following code: from typing import Any, Dict def main() -> None: my_str: str = 'hello' my_int: int = my_str if __name__ == "__main__": main() by outputting: error: Incompatible types in assignment (expression has type "str", variable has type "int") However the following code is accepted without any error: from typing import Any, Dict def main() -> None: my_str: Any = 'hello' my_int: int = my_str if __name__ == "__main__": main() Is there an option

Typing in jMeter

会有一股神秘感。 提交于 2019-12-11 03:26:18
问题 Is there any option how to simulate keyboard typing in jMeter? Ive got filter field with autosuggestions and I want to test response time of it. I want to start typing something like "W","Wa","Wash","Washi" etc. but for values loaded from CSV. 回答1: JMeter operates on HTTP protocol level, not browser level. Therefore you shouldn't try to emulate typing. What you can do is to capture (record) HTTP request triggered by such change, and later run this as part of your JMeter test. My advice is -

How to annotate attribute that can be implemented as property?

百般思念 提交于 2019-12-11 00:31:17
问题 I am trying to make mypy happy with my type annotations. Here is minimal example: class FooInterface: x: int class FooWithAttribute(FooInterface): x: int = 0 class FooWithProperty(FooInterface): @property def x(self) -> int: return 0 To my human understanding everything is fine: both FooWithAttribute().x and FooWithProperty().x will return 0 which is int , no type errors. However mypy complains: error: Signature of "x" incompatible with supertype "FooInterface" Is there a way to tell mypy

PHP's mixed type vs Typescript's any

感情迁移 提交于 2019-12-10 18:14:35
问题 I was trying out PHP's mixed type in a custom function, but this error has me stumped (punctuation is mine): TypeError: Argument 1 passed to <functionName>() must be an instance of mixed , string given. Below some (sample) code below that causes the error message and illustrates what I was hoping to achieve. Below that some TLDR with further explanation. But basicall I saw mixed as the type of parameters of some of PHP's native functions (for example the is_string function) and wanted to do

What does _r suffix mean?

孤人 提交于 2019-12-10 14:25:31
问题 I know _r suffix is used to indicate something thread-safe. For example strtok and strtok_r or libmysql.so and libmysql_r.so . But I cannot find anywhere what this actually means ? For example, _t means 'type' and what does _r suffix mean? 回答1: See Chapter A.4.16 Thread-Safety in http://pubs.opengroup.org/onlinepubs/000095399/xrat/xbd_chap04.html: The suffix "_r" is historical, where the 'r' stood for "reentrant". 回答2: The _r suffix stands for reentrant. 回答3: _r means reentrant, even though

mypy differences in isinstance and issubclass from python 3.5 to 3.6 in parameterized generics

社会主义新天地 提交于 2019-12-10 13:28:39
问题 Before I upgraded to python 3.6 from python 3.5 this worked: import typing issubclass(list, typing.List[int]) # returns True isinstance([1, 2 ,3], typing.List[int]) # returns True now in python 3.6 both of these raise the following exception: TypeError: Parameterized generics cannot be used with class or instance checks Is this new intended behavior or a bug? If it is intended how can I perform the checks the code above is doing in python 3.6? 回答1: It is intentional, you shouldn't be mixing

Complementary generic types

老子叫甜甜 提交于 2019-12-10 11:45:44
问题 Premise: In my project I have two generically typed interfaces defining Request and Response respectively. A request is processed to yield a response, hence every response is built based on a request. A Processor interface processes a request to build the corresponding response. Code: The request and response interfaces are: interface Request<T1> and interface Response<T2> respectively, where T2 and T1 represent generic request and response types (I am deliberately calling them by different

How to type hint a dictionary with values of different types

[亡魂溺海] 提交于 2019-12-10 04:35:43
问题 When declaring a dictionary as a literal, is there a way to type-hint what value I am expecting for a specific key? And then, for discussion: are there guiding principles around dictionary typing in Python? I'm wondering whether it is considered bad practice to mix types in dictionaries. Here's an example: Consider the declaration of a dictionary in a class's __init__ : (disclaimer: I realize in the example, some of the .elements entries would probably be more appropriate as class attributes,