Skip to main content
Stack Overflow
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
3 votes
1 answer
89 views

In order to narrow type into literal types, I usually do the following: from typing import Literal, TypeIs, get_args, reveal_type type OneTwoThree = Literal[1, 2, 3] type FourFiveSix = Literal[4, 5, ...
0 votes
1 answer
98 views

How to type libraries using ahk? I thought about doing it like this: class AHKMouseController: def __init__( self, ahk: AHK ): self._ahk = ahk But mypy complains: ...
Best practices
2 votes
2 replies
127 views

I am working with an application that uses Pydantic models extensively. Many attributes on these models are set to Optional but with a default value to ensure that they are not None. The intent is ...
Advice
1 vote
4 replies
127 views

I have a module (let's name it optional_module) that I want to be imported optionally, as it can be either present or absent. Now I do it this simple way: try: import optional_module except ...
Phant's user avatar
  • 43
3 votes
1 answer
136 views

I recently upgraded mypy from 1.17.0 to 1.18.2 The following code was successfully validated in the old mypy version (1.17.0), but fails in the new one (1.18.2): _T = TypeVar('_T') class Foo(Generic[...
Best practices
0 votes
3 replies
76 views

I'm working with a large, existing Python codebase. Recently someone noticed that one of the files in the testsuite wasn't being type checked by mypy and so suggested to run python -m mypy . rather ...
Newbyte's user avatar
  • 3,955
1 vote
2 answers
217 views

Objective I'm using mypy to type check my code. Locally, this works fine by running mypy --install-types once on setup. It installs e.g. scipy-stubs, because the stubs are in an extra package. It ...
Mo_'s user avatar
  • 2,101
-4 votes
1 answer
180 views

Is it possible to tell the type checker what the return type is by supplying an input argument, something like rtype here: from __future__ import annotations from typing import TypeVar T = ...
0 votes
1 answer
83 views

I have the following abstract Data class and some concrete subclasses: import abc from typing import TypeVar, Generic, Union from pydantic import BaseModel T = TypeVar('T') class Data(BaseModel, abc....
1 vote
0 answers
132 views

The Mypy docs state: If a directory contains both a .py and a .pyi file for the same module, the .pyi file takes precedence. This way you can easily add annotations for a module even if you don’t ...
lupl's user avatar
  • 974
1 vote
0 answers
136 views

When I define a class attribute named type, a type[Foo] annotation inside the same class causes mypy to report that the type name is a variable and therefore "not valid as a type". class Foo: type:...
2 votes
0 answers
87 views

I’m trying to implement a system where I use a Mediator class to execute queries and return results based on the type of QUERY passed. I also want to use a Handler class with a handle method that ...
0 votes
0 answers
74 views

Using Python and Qt5, I can make a normal signal connection like this: def clicked() -> None: print("clicked") btn = QtWidgets.QPushButton("Button", window) btn....
1 vote
1 answer
112 views

I have a callback from tkinter import font, ttk class Foo(ttk.Frame): def set_font_cb(self, event: tk.Event) -> None: event.widget.configure(font=font.Font(...)) And this creates in ...
0 votes
0 answers
127 views

I wanted to override the structlog logger for the whole application, by doing this: import enum from collections.abc import Iterable import structlog from structlog.typing import Processor from ...

15 30 50 per page
1
2 3 4 5
...
188

AltStyle によって変換されたページ (->オリジナル) /