typing

Python: All type hints errors in subclass constructure seems ignored

↘锁芯ラ 提交于 2019-12-25 01:33:14
问题 I have the following code with python type hints It has a bunch of errors. All erros in code are found by mypy but not the errors in constructor of S. Why? I cannot find out what is happening thanks code: import typing class T(object): def __init__(self, a: int, b: str = None) -> None: self.a = a self.b: typing.Union[str, None] = b self._callback_map: typing.Dict[str, str] = {} class S(T): def __init__(self): super().__init__(self, 1, 2) self._callback_map[1] = "TOTO" s = T(1, 1) t = T(1, b=2

Relative paths. baseUrl and paths not working on ionic2 - angular2

淺唱寂寞╮ 提交于 2019-12-24 05:55:48
问题 I've been reading on similar stack overflows but I haven't been able to figure it out. I must be missing a little step. My goal is to be able to do: import { Logger } from 'logging' instead of import { Logger } from '../../modules/logging' My tsconfig looks like this: { "compilerOptions": { "allowSyntheticDefaultImports": true, "declaration": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, "lib": [ "dom", "es2015" ], "module": "commonjs", "moduleResolution": "node",

Function returning result of any constructor of a GADT

余生颓废 提交于 2019-12-24 01:47:06
问题 I'm currently having a fight with the typechecker when I try to create a function returning Thing a (where Thing is a GADT). A minimal contrived example: {-#LANGUAGE GADTs, EmptyDataDecls #-} module Main where -- Define a contrived GADT data TFoo data TBar data Thing a where Foo :: Int -> Thing TFoo Bar :: String -> Thing TBar combine :: [Thing a] combine = [Foo 1, Bar "abc"] main :: IO () main = undefined The typechecker gets unhappy that a doesn't match TBar . Presumably this is because it

Javascript typing (Int/String) question

余生长醉 提交于 2019-12-24 00:53:03
问题 I have encountered something weird (probably not, it's more likely that I don't really get it) in JavaScript and I'd be curious to find out why things behave like they do. When I do: var index = '1'; index++; alert(index); index = index + 1; alert(index); index = true ? index + 1 : 0; alert(index); as in http://jsfiddle.net/5mdmJ/ the alerts will go "2", "3", "4" When I reverse the order and do this (http://jsfiddle.net/5mdmJ/1/): var index = '1'; index = true ? index + 1 : 0; alert(index);

mypy: Signature of “__getitem__” incompatible with supertype “Sequence”

白昼怎懂夜的黑 提交于 2019-12-23 09:40:34
问题 I have a class that inherits from MutableSequence like this: class QqTag(MutableSequence): def __init__(self): self._children = [] def __getitem__(self, idx: int) -> 'QqTag': return self._children[idx] mypy complains that Signature of "__getitem__" incompatible with supertype "Sequence" . In Sequence , this method is defined as: @abstractmethod def __getitem__(self, index): raise IndexError So, what's the problem and why mypy isn't happy with my implementation? 回答1: As mentioned in comments,

How can I pass `this` to a constructor without circular references (or losing type) in c++?

自作多情 提交于 2019-12-23 01:03:26
问题 EDIT: this has been marked as a duplicate. I believe there is a distinction between Q: what can I use to solve my problem, A: this thing ~and~ Q: what is this thing? A: big huge in depth answer. I'm not sure what the official ruling on this is though. I have two classes which both need to know about each other // Creator.h #pragma once #include "Creation.h" class Creator { Creator() { myThing = new Creation(*this); } int age = 42; Creation myThing*; } . // Creation.h #pragma once #include

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

为君一笑 提交于 2019-12-22 01:33:48
问题 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',

What is the PHP best practice for using functions that return true or false?

折月煮酒 提交于 2019-12-19 08:00:36
问题 After playing with PHP, I discovered that true is returned as 1 and false as null. echo (5 == 5) // displays 1 echo (5 == 4) // displays nothing When writing functions that return true or false, what are the best practices for using them? For example, function IsValidInput($input) { if ($input...) { return true; } else { return false; } } Is this the best way to use the function? if (IsValidInput($input)) { ... } How would you write the opposite function? IsBadInput($input) { return !

Converting OCaml to F#: Differences between typing and type inference

混江龙づ霸主 提交于 2019-12-19 06:01:29
问题 In researching type inference differences between F# and OCaml I found they tended to focus on nominative vs. structural type system. Then I found Distinctive traits of functional programming languages which list typing and type inference as different traits. Since the trait article says OCaml and F# both use Damas-Milner type inference which I thought was a standard algorithm, i.e. an algorithm that does not allow for variations, how do the two traits relate? Is it that Damas-Milner is the

Generic NamedTuple in Python 3.6

喜欢而已 提交于 2019-12-19 03:40:10
问题 I'm trying to create a generic version of a NamedTuple, as follows: T1 = TypeVar("T1") T2 = TypeVar("T2") class Group(NamedTuple, Generic[T1, T2]): key: T1 group: List[T2] g = Group(1, [""]) # expecting type to be Group[int, str] However, I get the following error: TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases I'm not sure how else to achieve what I'm trying to do here, or if this might be a bug in the