typing

How to define a regex-matched string type in Typescript?

耗尽温柔 提交于 2019-11-30 18:42:53
Is it possible to define an interface which has some information on the format of a string? Take the following example: interface timeMarkers{ markerTime: string[] }; an example would be: { markerTime: ["0:00","1:30", "1:48"] } My question: Is there a way to define the type for markerTime such that that the string value must always match this regex, instead of declaring it as simply string[] and going from there? var reg = /[0-9]?[0-9]:[0-9][0-9]/; There is no way to define such a type. There is a proposal on GitHub to support this, but it currently does not appear to be a priority. Vote on it

Is Perl weakly or strongly typed?

我的梦境 提交于 2019-11-30 18:28:58
I am currently learning Perl 5 from learn.perl.org and I am curious about its typing system. I see mixed information about Perl being weakly or strongly typed, and that it is also dynamically typed. Wikipedia states that it also supports duck typing. Can anyone confirm its weakly or strongly typed nature? I see mixed information about Perl being weakly or strongly typed That's no surprise given that there is also conflicting information as to whether C is a strongly-typed or weakly-typed language. An example for a statically, but weakly typed language is C. [ source ] C is strongly typed... [

Python typing for module type

懵懂的女人 提交于 2019-11-30 17:33:53
I am dynamically loading a Python module using importlib.import_module as follows def load_module(mod_name: str) -> ???: return importlib.import_module(mod_name) Can somebody tell me what is the correct type annotation for a module type. The typing module does not contain one and I could not find an answer elsewhere. You're looking for types.ModuleType . 来源: https://stackoverflow.com/questions/48389157/python-typing-for-module-type

Typing while animation UITextView

房东的猫 提交于 2019-11-30 16:08:10
I'm trying to have a variable-height UITextView which changes size to accomodate its contents, but when the frame changes in the size-change animation, one or two keystrokes aren't captured in the UITextView. The animation duration is 0.1s, and typically it only misses one letter when you're typing fairly fast. It is, however, very consistent in missing letters when the animation happens. The following animation block occurs within the textViewDidChange: delegate message: [UIView animateWithDuration:0.1 animations:^{ [textView setFrame:CGRectMake(...)]; }]; I've Googled and searched on SO, but

Python: Can a class forbid clients setting new attributes?

十年热恋 提交于 2019-11-30 12:35:31
I just spent too long on a bug like the following: >>> class Odp(): def __init__(self): self.foo = "bar" >>> o = Odp() >>> o.raw_foo = 3 # oops - meant o.foo I have a class with an attribute. I was trying to set it, and wondering why it had no effect. Then, I went back to the original class definition, and saw that the attribute was named something slightly different. Thus, I was creating/setting a new attribute instead of the one meant to. First off, isn't this exactly the type of error that statically-typed languages are supposed to prevent? In this case, what is the advantage of dynamic

C# “is” operator - is that reflection?

随声附和 提交于 2019-11-30 04:29:37
A colleague asked me an interesting question today - is the C# keyword/operator "is" considered reflection? object tmp = "a string"; if(tmp is String) { } How is this operator implemented behind the scenes? Does it require reflection or introspection? Or because of the strongly typed nature of the language, is the Type of the object immediately accessable as a top-level attribute of the object in memory? MSDN states that: Note that the is operator only considers reference conversions, boxing conversions, and unboxing conversions. Other conversions, such as user-defined conversions, are not

Type annotations for *args and **kwargs

ⅰ亾dé卋堺 提交于 2019-11-30 02:32:39
I'm trying out Python's type annotations with abstract base classes to write some interfaces. Is there a way to annotate the possible types of *args and **kwargs ? For example, how would one express that the sensible arguments to a function are either an int or two int s? type(args) gives Tuple so my guess was to annotate the type as Union[Tuple[int, int], Tuple[int]] , but this doesn't work. from typing import Union, Tuple def foo(*args: Union[Tuple[int, int], Tuple[int]]): try: i, j = args return i + j except ValueError: assert len(args) == 1 i = args[0] return i # ok print(foo((1,))) print

Google Closure Compiler 100% typed

夙愿已清 提交于 2019-11-30 02:20:27
How can I get my application to be 100% typed in regard to google closure compiler? I already tagged everything with jsdoc comments. Is it even possible to get 100? I'm at 64,6% kayahr It IS possible to achieve 100%. My own projects are 100% typed. The closure compiler can output warnings about expressions with unknown types. Unfortunately there is no command line option to enable this feature. You have to modify the source code to enable it: Download the current sources: git clone https://code.google.com/p/closure-compiler/ Edit src/com/google/javascript/jscomp/CompilerOptions.java and change

Dynamic typing, Objective-C, how does it work?

ε祈祈猫儿з 提交于 2019-11-30 02:13:04
I'm interested in how does dynamic typing in Objective-C work. I've been studying the "id" type, I know what it does and how to use it, but I'm curious... How does such functionality get implemented under the hood? You cannot determine/resolve anything during compile time, only during runtime. I guess it can simply just point to the first byte of some object in memory, but how is the class signature stored? How does it know what is it currently pointing towards and how does it implement various getters for the class of the pointed object? "Under the hood", so to speak, all Objective-C objects

typed python: using the classes' own type inside class definition [duplicate]

試著忘記壹切 提交于 2019-11-29 17:33:17
This question already has an answer here: Self-reference or forward-reference of type annotations in Python [duplicate] 1 answer How do I specify that the return type of a method is the same as the class itself? 3 answers The following code does not work as expected. Apparently, I cannot use the classes' own type inside class definition: class Foo: def __init__(self, key :str) -> None: self.key = key def __eq__(self, other :Foo) -> bool: return self.key == other.key print('should be true: ', Foo('abc') == Foo('abc')) print('should be false: ', Foo('abc') == Foo('def')) The result of running it