typing

How to type hint a dictionary with values of different types

霸气de小男生 提交于 2019-12-05 08:08:29
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, but it's for the sake of the example). class Rectangle: def __init__(self, corners: Tuple[Tuple[float,

Untyped / typeless parameters in Delphi

佐手、 提交于 2019-12-05 00:54:10
What type are parameters without type like in the class TStringStream: function Read(var Buffer; Count: Longint): Longint; override; What is the type of Buffer parameter (is it a type of Pointer ?). Rob Kennedy I wrote an article about this very topic a few years ago: What is an untyped parameter? Untyped parameters are used in a few situations; the TStream.Read method you ask about most closely matches with the Move procedure I wrote about. Here's an excerpt: procedure Move(const Source; var Dest; Count: Integer); The Move procedure copies data from an arbitrary variable into any other

F#, Nominative or Structural Typed

岁酱吖の 提交于 2019-12-05 00:32:39
Does F# have a Nominative Type System or a Structural Type System? I know that OCaml is structurally typed, though F# doesn't seems to be so, is this correct? F# is nominative. You can do a few structural tricks via some exotic mechanisms, but the type system of the language is primarily nominative. 来源: https://stackoverflow.com/questions/3137512/f-nominative-or-structural-typed

What's the correct way to check if an object is a typing.Generic?

送分小仙女□ 提交于 2019-12-04 23:59:53
I'm trying to write code that validates type hints, and in order to do so I have to find out what kind of object the annotation is. For example, consider this snippet that's supposed to tell the user what kind of value is expected: import typing typ = typing.Union[int, str] if issubclass(typ, typing.Union): print('value type should be one of', typ.__args__) elif issubclass(typ, typing.Generic): print('value type should be a structure of', typ.__args__[0]) else: print('value type should be', typ) This should print "value type should be one of (int, str)", but instead it throws an exception:

how to type hint collections.OrderedDict via python 3.5 typing module

删除回忆录丶 提交于 2019-12-04 22:34:29
I want to use an OrderedDict where the key is a Enum and where the item is a certain class. How do I use the typing module to hint this? What is the analog to this hinted namedtuple:: Move = typing.NamedTuple('Move', [('actor', Actor), ('location', Location)]) As noted in a comment by AChampion, you can use MutableMapping : class Actor(Enum): # ...Actor enum menbers... class Location: # ...Location class body... class MapActor2Location(OrderedDict, MutableMapping[Actor, Location]): pass Addendum for people like me who haven't used the typing module before: note that the type definitions use

Jquery with Typescript : Property 'css' does not exist on type 'ElementFinder'

廉价感情. 提交于 2019-12-04 20:03:11
I'm trying to use jquery in my angular2 project which is getting build with webpack . I got the webpack angular2 starter kit from here : here However ,I can't figure out how to get rid of these errors as my build is failing because of them . This is my typings.json { "globalDependencies": { "angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459", "angular2-beta-to-rc-alias": "file:./node_modules/@angularclass/angular2-beta-to-rc-alias/src/beta-17/typings.d.ts", "core-js": "registry:dt/core-js#0.0.0+20160317120654", "hammerjs": "registry:dt/hammerjs#2.0.4+20160417130828",

How to minimize use of arrow keys when typing code?

吃可爱长大的小学妹 提交于 2019-12-04 16:35:03
问题 When typing code, I would normally close brackets, go back inside, go outside, type semicolon, etc: I might start with (| is the caret): System.out.println()| Then go left: System.out.println(|) Then this: System.out.println(foo()|) Again backtracking a space: System.out.println(foo(|)) Typing quotes are similar: System.out.println(foo(""|)) ...etc. My right hand is constantly moving between the home row and the arrow keys. I've tried vim and although I know the basics, it still feels very

Typing in a IFrame with Selenium IDE

删除回忆录丶 提交于 2019-12-04 14:54:13
I'd like to type something in a IFrame with Selenium IDE but I don't know how to do this. Thanks a lot! You have to select the iframe and then type selenium.selectFrame("css=iframe.widget[<a_css_identifier>]"); selenium.type(<your_object_or_text_box>, <typed_content>); The statements are in java, but you should be able to find selectFrame and type in the IDE. You can use the Selenium IDE command 'selectFrame' to focus within an iframe. Use the Target field to enter the iframe id. Try <tr> <td>selectFrame</td> <td>edit</td> <td></td> </tr> <tr> <td>type</td> <td>xpath=//html/body</td> <td>my

Increase typing speed? [closed]

浪子不回头ぞ 提交于 2019-12-04 14:48:22
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 years ago . It has recently been brought to my attention that my typing skills leave much to be desired. I've been programming a few years in college now, and typing speed has never been very important. Classes do not focus on how much code you can output, but instead how to design and implement code. Now that I have a job however, demands have changed slightly and I think it in my benefit to increase my typing skills, at

Is there a compiled* programming language with dynamic, maybe even weak typing?

回眸只為那壹抹淺笑 提交于 2019-12-04 09:53:27
问题 I wondered if there is a programming language which compiles to machine code/binary (not bytecode then executed by a VM, that's something completely different when considering typing) that features dynamic and/or weak typing, e.g: Think of a compiled language where: Variables don't need to be declared Variables can be created during runtime Functions can return values of different types Questions: Is there such a programming language? (Why) not? I think that a dynamically yet strong typed,