ICode9

精准搜索请尝试: 精确搜索
  • Python 静态分析Pylint、Pyflakes 与 Mypy ——我应该用谁?2020-12-03 07:01:17

    Python 静态分析Pylint、Pyflakes 与 Mypy ——我应该用谁? 摄影:产品经理黄金炒饭配麻婆豆腐说到 Python 的静态分析工具,就不得不说Pylint、Pyflakes 和 Mypy。他们的作用有重叠的地方,但又有各自的侧重点。在某些时候你可以只选择其中一个来用,有时候你又需要把他们结合起来使用。 P

  • python-如何对具有可选参数的装饰器进行类型注释?2019-12-11 01:58:26

    这是我要正确键入注释的确切函数: F = TypeVar('F', bound=Callable[..., Any]) def throtle(_func: Optional[F] = None, *, rate: float = 1) -> Union[F, Callable[[F], F]]: """Throtles a function call, so that at minimum it can be called every

  • python-mypy“无效类型”错误2019-11-18 09:56:24

    我正在尝试在当前项目中实现类型注释,并且从mypy接收到了我不理解的错误. 我正在使用Python 2.7.11,并将新安装的mypy安装在基本virtualenv中.以下程序运行正常: from __future__ import print_function from types import StringTypes from typing import List, Union, Callable

  • python-即使测试了所有情况,MyPy也会给出错误“ Missing return statement”2019-11-10 21:08:39

    即使在检查函数中所有可能的情况时,我也收到MyPy错误“缺少返回语句”. 例如,在下面的代码中,即使颜色只能是Color.RED,Color.GREEN或Color.BLUE,MyPy仍然给我一个错误“ 9:错误:缺少返回语句”,并且我测试了所有这些情况! class Color(enum.IntEnum): RED: int = 1 GREEN: i

  • python-自定义type.NamedTuple2019-11-09 02:00:04

    我正在使用NamedTuples来保存数据,并且我想添加一个可由多个基于NamedTuple的类继承的方法.但是,当我尝试使用多重继承或基于NamedTuple的类的子类化时,它不起作用.具体来说,我试图为所有数据类自动提供一种方法,该方法可以查看类注释,然后基于此方法调用一些序列化代码.以下是我尝

  • 在Python 3.x中是否可以进行类型化的隐式转换(强制转换)?2019-10-25 04:57:03

    是否可以在Python 3.6中实现自定义的自动/隐式转换(也称为强制转换),而不会使mypy和其他静态分析器感到难过?一个示例是def(foo:A),并给出def b_to_a(b:B)-> A,有没有一种方法可以代替foo(b_to_a(some_b))来写foo(some_b)(其中some_b:B)? 我认为在Python的动态特性中肯定有一些好的方法(

  • python – mypy,type提示:Union [float,int] – >是否有Number类型?2019-09-10 18:57:08

    mypy非常方便并且捕获了很多错误,但是当我编写“科学”应用程序时,我经常最终会这样做: def my_func(number: Union[float, int]): # Do something number是float或int,具体取决于用户的输入.有官方的方法吗?解决方法:仅使用float,因为int隐含在该类型中: def my_func(number:

  • python – mypy:基类没有属性x,如何在基类中键入提示2019-08-23 10:55:47

    我最近发现了mypy,我希望我的代码可以用它进行类型检查. 我有一个Connector基类: class Connector(): ... some methods, but no __init__ ... 我有几个子类,它们都是连接器,但有不同的类型: class Siphon(Connector) def __init__(): short_name = "S" class T

  • python – mypy:与超类型不兼容的方法的参数2019-07-10 13:06:36

    查看示例代码(mypy_test.py): import typing class Base: def fun(self, a: str): pass SomeType = typing.NewType('SomeType', str) class Derived(Base): def fun(self, a: SomeType): pass 现在mypy抱怨: mypy mypy_test.py mypy_test.py:1

  • 键入一个函数参数,该函数参数派生自Python中的多个抽象基类2019-07-06 07:56:40

    我试图根据PEP 484在Python 2中键入一个函数注释.该函数接受一个应该同时实现__len__和__iter__的容器.我想要添加此注释的原始代码非常复杂,因此请考虑一个示例函数,如果len(s)是偶数,则返回容器中所有int的乘积,否则返回1. 如果我想要注释只需要__len__的容器,我会将其注释为类型

  • python – 键入:声明输入时不兼容的类型.Type []2019-07-06 00:55:54

    对于以下代码 # -*- coding: utf-8 -*- import typing class A(object): pass class B(A): pass class C(A): pass class D(A): pass class E(A): pass MAPPING_X = { B: 'b', C: 'c', } MAPPING_Y = { D: 'd

  • python – 将生成器函数注释为迭代器的混淆2019-07-01 12:44:05

    在python typing文档中写道: Alternatively, annotate your generator as having a return type of either Iterable[YieldType] or Iterator[YieldType]: def infinite_stream(start: int) -> Iterator[int]: while True: yield start start += 1 我写了一

  • python – 如何键入注释csv.writer返回的对象?2019-05-22 15:46:04

    我想将类型注释应用于返回的csv.writer对象,以符合更大的代码库.不幸的是我无法弄清楚拟合返回类型. >>> import csv >>> writer = csv.writer(open('outfile.csv', 'w')) >>> type(writer) <class '_csv.writer'> 如果我尝试使用此类名: >>> import

  • 推导式2019-04-14 13:55:07

    生成指定序列列表(程序生成) lst = [] for i in range(1,6): lst.append('python_%d' % i) print(lst) 结果:F:\myPy\venv\Scripts\python.exe F:/myPy/test.py['python_1', 'python_2', 'python_3', 'python_4', 'python_5&#

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有