typing

How to type faster [closed]

不羁的心 提交于 2019-11-28 16:14:21
I've typed around 75wpm for the last few years but I've always wondered how people type +100wpm. I've searched but I primarily find typing tutors that teach you to type.. not teach you to type faster. So far the only tip I've come across is to learn dvorak. Are there exercises or tips to help break through the 75wpm wall? Setting yourself up in an ergonomic typing position is a good start. Take a look at the diagram here - notice the arms in a straight line, feet on the floor, etc. In my experience most people tend to slow down when they get to unusual keys - numbers, symbols, punctuation, etc

A way to subclass NamedTuple for purposes of typechecking

主宰稳场 提交于 2019-11-28 12:03:15
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_extended) When I run mypy on this code I get a predictable error: mypy_example.py:20: error: Argument 1

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

雨燕双飞 提交于 2019-11-28 11:32:32
问题 This question already has answers 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? (4 answers) Closed 2 years ago . 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

Correct way to write type hints for keys and items

泄露秘密 提交于 2019-11-28 06:54:54
问题 I have some Python code (running for Python 3.5, 3.6 and 3.7) and added some type hints for static type checks using mypy. Please take a look at the following snippet: class MyParams(Singleton, metaclass=MyParamsMeta): @classmethod def keys(cls): # TODO -> type? return cls._params.keys() @classmethod def items(cls): # TODO -> type? return cls._params.items() _params = _load_from_csv() # returns Dict[str, MyParam] What are the correct type hint statements for def keys(cls) and def items(cls) ?

Can't rely on target typing when chaining methods [closed]

瘦欲@ 提交于 2019-11-28 01:27:48
问题 In Java 8, type inference has been extended to target typing which enables to write: Comparator<String> ascending = comparingInt(String::length); without having to use a type witness ( Comparator.<String> comparingInt ). However the last statement below does not compile. Is there a reason? Is there a workaround? Comparator<String> ascending = comparingInt(String::length); //ok Comparator<String> descending = ascending.reversed(); //ok Comparator<String> descending = reverseOrder(comparingInt

Java isInstance vs instanceOf operator

僤鯓⒐⒋嵵緔 提交于 2019-11-27 21:10:50
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 the actual helper. It does some casting and object creation. What I am seeing is that there is no match

Automatically closing braces in Emacs?

喜欢而已 提交于 2019-11-27 20:26:36
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! There's also 'paredit . The cheat sheet shows you all the commands available. happen to like it better than the electric mode suggested in another answer. Though paredit does only apply to (), so it may not meed your needs. But, to

How can I type-check variables in Python?

六月ゝ 毕业季﹏ 提交于 2019-11-27 17:08:16
问题 I have a Python function that takes a numeric argument that must be an integer in order for it behave correctly. What is the preferred way of verifying this in Python? My first reaction is to do something like this: def isInteger(n): return int(n) == n But I can't help thinking that this is 1) expensive 2) ugly and 3) subject to the tender mercies of machine epsilon. Does Python provide any native means of type checking variables? Or is this considered to be a violation of the language's

What is Dynamic Typing?

ε祈祈猫儿з 提交于 2019-11-27 16:24:49
问题 I've heard this term used with scripting languages such as PHP. What exactly does it mean? 回答1: Dynamic typing is a definitive characteristic of a language. A short explanation might be: A language has dynamic typing when it does not associate values strictly with a specific type, but it is designed to "decide" what the type of a value should be at runtime, based on how you are attempting to use it. For example, in PHP you can write $count = "5"; // defines a string variable and then go on to

Validating detailed types in python dataclasses

♀尐吖头ヾ 提交于 2019-11-27 12:52:19
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 methods :) But one other thing that I wanted to try was forcing the type hints as conditions during runtime, i.e.