typechecking

ESLint not reporting TypeScript compiler type checking errors

若如初见. 提交于 2020-12-25 04:00:47
问题 Looking for help in getting the type errors, reported by the TypeScript compiler, into the output of ESLint. The library typescript-eslint (https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md) makes me think that this should be possible. File structure src/ ... source files tsconfig.json test/ ... testing files .eslintrc.js package.json tsconfig.json (symlink to src/tsconfig.json) .eslintrc.js module.exports = { 'env': { 'jest':

Typechecking dynamically added attributes

◇◆丶佛笑我妖孽 提交于 2020-12-03 07:43:07
问题 When writing project-specific pytest plugins, I often find the Config object useful to attach my own properties. Example: from _pytest.config import Config def pytest_configure(config: Config) -> None: config.fizz = "buzz" def pytest_unconfigure(config: Config) -> None: print(config.fizz) Obviously, there's no fizz attribute in _pytest.config.Config class, so running mypy over the above snippet yields conftest.py:5: error: "Config" has no attribute "fizz" conftest.py:8: error: "Config" has no

Does mypy only type check a function if it declares a return type?

让人想犯罪 __ 提交于 2020-11-29 19:25:42
问题 The following file: from typing import List class A: def __init__(self, myStr): self.chars: List[int] = list(myStr) def toString(self): return "".join(self.chars) typechecks (note chars should be List[str] not List[int]): ➜ Python python3 -m mypy temp.py => Success: no issues found in 1 source file , but the following one, where I declare the return type of toString, does: from typing import List class A: def __init__(self, myStr): self.chars: List[int] = list(myStr) def toString(self) -> str

Does mypy only type check a function if it declares a return type?

主宰稳场 提交于 2020-11-29 19:25:38
问题 The following file: from typing import List class A: def __init__(self, myStr): self.chars: List[int] = list(myStr) def toString(self): return "".join(self.chars) typechecks (note chars should be List[str] not List[int]): ➜ Python python3 -m mypy temp.py => Success: no issues found in 1 source file , but the following one, where I declare the return type of toString, does: from typing import List class A: def __init__(self, myStr): self.chars: List[int] = list(myStr) def toString(self) -> str

Rust “expected type” error prints mismatched types that are exactly the same

断了今生、忘了曾经 提交于 2020-06-27 09:59:05
问题 With nightly rust: Playground struct Foo<T, F: Fn(&T, &T) -> T> { value: T, func: F } fn main() { let lambda = |&x, &y| x + y; let foo = Foo { value: 5 as i32, func: lambda }; } Error message: Compiling playground v0.0.1 (/playground) error[E0308]: mismatched types --> src/main.rs:8:15 | 8 | let foo = Foo { | ^^^ one type is more general than the other | = note: expected type `std::ops::FnOnce<(&i32, &i32)>` found type `std::ops::FnOnce<(&i32, &i32)>` Note that the expected type and found

How to get Mypy to realize that sorting two ints gives back two ints

人走茶凉 提交于 2020-06-17 01:57:32
问题 My code is as follows: from typing import Tuple a: Tuple[int, int] = tuple(sorted([1, 3])) Mypy tells me: Incompatible types in assignment (expression has type "Tuple[int, ...]", variable has type "Tuple[int, int]") What am I doing wrong? Why can't Mypy figure out that the sorted tuple will give back exactly two integers? 回答1: The call to sorted produces a List[int] which carries no information about length. As such, producing a tuple from it also has no information about the length. The

Java - How do I create an annotation type that is only applicable in type contexts? (PURE type annotation)

这一生的挚爱 提交于 2020-05-28 09:38:33
问题 To create a type annotation that is applicable in type contexts, there is no way other than meta-annotating the annotation type with @Target(ElementType.TYPE_USE) . However, this annotation also becomes applicable in declaration contexts due to the bad decision of the Java designers. According to the Java SE documentation, it reads: The constant TYPE_USE corresponds to the type contexts in JLS 4.11, as well as to two declaration contexts: type declarations (including annotation type

Java - How do I create an annotation type that is only applicable in type contexts? (PURE type annotation)

青春壹個敷衍的年華 提交于 2020-05-28 09:37:46
问题 To create a type annotation that is applicable in type contexts, there is no way other than meta-annotating the annotation type with @Target(ElementType.TYPE_USE) . However, this annotation also becomes applicable in declaration contexts due to the bad decision of the Java designers. According to the Java SE documentation, it reads: The constant TYPE_USE corresponds to the type contexts in JLS 4.11, as well as to two declaration contexts: type declarations (including annotation type

Java - How do I create an annotation type that is only applicable in type contexts? (PURE type annotation)

萝らか妹 提交于 2020-05-28 09:36:54
问题 To create a type annotation that is applicable in type contexts, there is no way other than meta-annotating the annotation type with @Target(ElementType.TYPE_USE) . However, this annotation also becomes applicable in declaration contexts due to the bad decision of the Java designers. According to the Java SE documentation, it reads: The constant TYPE_USE corresponds to the type contexts in JLS 4.11, as well as to two declaration contexts: type declarations (including annotation type

Java - How do I create an annotation type that is only applicable in type contexts? (PURE type annotation)

自作多情 提交于 2020-05-28 09:36:10
问题 To create a type annotation that is applicable in type contexts, there is no way other than meta-annotating the annotation type with @Target(ElementType.TYPE_USE) . However, this annotation also becomes applicable in declaration contexts due to the bad decision of the Java designers. According to the Java SE documentation, it reads: The constant TYPE_USE corresponds to the type contexts in JLS 4.11, as well as to two declaration contexts: type declarations (including annotation type