typing

typing animated text

谁说我不能喝 提交于 2019-11-27 12:28:48
问题 I have DIV tag with text inside. Is it possible to change the text content in a loop with a typing effect, where it types out, then goes backward deleting the letters and starting all over with a new text? Is this possible with jquery? 回答1: Just a simple approach: $("[data-typer]").attr("data-typer", function(i, txt) { var $typer = $(this), tot = txt.length, pauseMax = 300, pauseMin = 60, ch = 0; (function typeIt() { if (ch > tot) return; $typer.text(txt.substring(0, ch++)); setTimeout(typeIt

Type annotations for *args and **kwargs

荒凉一梦 提交于 2019-11-27 11:24:04
问题 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

Self-reference or forward-reference of type annotations in Python [duplicate]

早过忘川 提交于 2019-11-27 09:27:10
This question already has an answer here: Type hints: solve circular dependency 2 answers I'm trying to figure out how self-reference of types work with python3's type annotations - the docs don't specify anything regarding this. As an example: from typing import TypeVar, Optional, Generic T = TypeVar('T') class Node(Generic[T]): left = None right = None value = None def __init__( self, value: Optional[T], left: Optional[Node[T]]=None, right: Optional[Node[T]]=None, ) -> None: self.value = value self.left = left self.right = right This code generates the error: Traceback (most recent call last

Does “untyped” also mean “dynamically typed” in the academic CS world?

╄→尐↘猪︶ㄣ 提交于 2019-11-27 05:51:50
I'm reading a slide deck that states "JavaScript is untyped." This contradicted what I thought to be true so I started digging to try and learn more. Every answer to Is JavaScript an untyped language? says that JavaScript is not untyped and offered examples of various forms of static, dynamic, strong, and weak typing that I'm familiar and happy with.. so that wasn't the way to go. So I asked Brendan Eich, the creator of JavaScript, and he said: academic types use "untyped" to mean "no static types". they are smart enough to see that values have types (duh!). context matters. Do academically

A way to subclass NamedTuple for purposes of typechecking

霸气de小男生 提交于 2019-11-27 03:55:23
问题 I have several namedtuples that share some fields. I have a function that accepts these tuples and is guaranteed to only interact with the shared fields. I want to typecheck such code in mypy. An example of the code would be: from typing import NamedTuple class Base(NamedTuple): x: int y: int class BaseExtended(NamedTuple): x: int y: int z: str def DoSomething(tuple: Base): return tuple.x + tuple.y base = Base(3, 4) base_extended = BaseExtended(5, 6, 'foo') DoSomething(base) DoSomething(base

Java isInstance vs instanceOf operator

我是研究僧i 提交于 2019-11-26 23:01:02
问题 The whole generics thing is kinda throwing me for a loop, and more so the RTT. Specificis? Ah well here's the gist: enum QueryHelper { query1, query2; static <T> QueryHelper getQueryHelper (Class<T> expectedReturn) { if (expectedReturn.isInstance (SomeRelatedClass.class)) return query1; else return query2; } } and then I would call it like so: ... QueryHelper helper = QueryHelper.getQueryHelper(SomeRelatedClass.class); ... This is so that I can really flexibly assign the query return type in

Automatically closing braces in Emacs?

纵然是瞬间 提交于 2019-11-26 20:21:28
问题 I've seen a plugin for Vim called AutoClose (discovered from this post) which automatically adds the closing brace when typing '(', '{' etc. For example; when I type the following ( | is the cursor): int main(| I would like the closing ) to be inserted automatically for me: int main(|) Does anyone know of a similar feature for emacs - Google has failed me this time! 回答1: There's also 'paredit. The cheat sheet shows you all the commands available. happen to like it better than the electric

Self-reference or forward-reference of type annotations in Python [duplicate]

血红的双手。 提交于 2019-11-26 17:50:33
问题 This question already has an answer here: How do I specify that the return type of a method is the same as the class itself? 4 answers I'm trying to figure out how self-reference of types work with python3's type annotations - the docs don't specify anything regarding this. As an example: from typing import TypeVar, Optional, Generic T = TypeVar('T') class Node(Generic[T]): left = None right = None value = None def __init__( self, value: Optional[T], left: Optional[Node[T]]=None, right:

Does “untyped” also mean “dynamically typed” in the academic CS world?

耗尽温柔 提交于 2019-11-26 11:47:53
问题 I\'m reading a slide deck that states \"JavaScript is untyped.\" This contradicted what I thought to be true so I started digging to try and learn more. Every answer to Is JavaScript an untyped language? says that JavaScript is not untyped and offered examples of various forms of static, dynamic, strong, and weak typing that I\'m familiar and happy with.. so that wasn\'t the way to go. So I asked Brendan Eich, the creator of JavaScript, and he said: academic types use \"untyped\" to mean \"no

Validating detailed types in python dataclasses

烈酒焚心 提交于 2019-11-26 11:04:32
问题 Python 3.7 is around the corner, and I wanted to test some of the fancy new dataclass +typing features. Getting hints to work right is easy enough, with both native types and those from the typing module: >>> import dataclasses >>> import typing as ty >>> ... @dataclasses.dataclass ... class Structure: ... a_str: str ... a_str_list: ty.List[str] ... >>> my_struct = Structure(a_str=\'test\', a_str_list=[\'t\', \'e\', \'s\', \'t\']) >>> my_struct.a_str_list[0]. # IDE suggests all the string