Skip to main content
1 vote
0 answers
27 views

Why doesn't mypy follow config in GitHub Actions?

If I run mypy locally it will only type check certain files because the pyproject.toml file has the following inclusion: [tool.mypy] files = [ "python/project/file1.py", "python/...
Attack68's user avatar
  • 4,758
1 vote
0 answers
93 views

Mypy plugin `get_method_hook` missing `body` in `ClassDef` for imported type

I'm having an issue with the get_method_hook in a simple mypy plugin. I'm not sure if it's a bug in mypy or if I have wrong expectations about the availability of information at a certain stage. The ...
DEls's user avatar
  • 251
0 votes
1 answer
26 views

Use attrs or_ validator with mypy

I'm trying to use attrs to define a class that has an attribute that can be either a str or an int. The or_ validator see;s to be exactly what I need but mypy throws an error when using the exact ...
I like Bananas's user avatar
0 votes
1 answer
36 views

How to type hint a decorator to dictate some parameters but not all?

I'm looking of a way (the way) to type hint a decorator indicating the parameters that must exist only. The decorator does not change the signature of the function it wraps. from functools import ...
Philip Couling's user avatar
0 votes
0 answers
29 views

Use of subclasses of Generic in other classes

I am again fighting against the use of bound type variable in python. Have a look at this example: from typing import Generic, TypeVar, Any ParameterType = TypeVar('ParameterType') class Parameter(...
toto's user avatar
  • 313
0 votes
1 answer
29 views

Access container class from contained class with python dataclasses

I have a parent class, that contains a child class. Both are implemented with python dataclasses. The classes look like this: from __future__ import annotations from dataclasses import dataclass @...
Hazel's user avatar
  • 175
0 votes
1 answer
40 views

Understanding unbound type error with mypy

I am new to static type checking in python and honestly I believed it was much easier that what it actually is. Here is an ultra simplified version of my code: from typing import Collection, TypeVar, ...
toto's user avatar
  • 313
0 votes
0 answers
54 views

How can I fix pycham wrong django type hint

from django.db.models import QuerySet member_meta_models: QuerySet[MemberWantedMetaModel] = MemberWantedMetaModel.objects.filter(member_id=member_id) Pycharm says Expected type QuerySet[...
은창현's user avatar
4 votes
2 answers
112 views

Python generic type on function getting lost somewhere

Getting this typing error: error: Incompatible types in assignment (expression has type "object", variable has type "A | B") [assignment] With this code: from dataclasses import ...
sixtyfootersdude's user avatar
1 vote
1 answer
104 views

What should typing be for __add__ in a subclass of list?

This is a simplification of my code: # my_list.py from __future__ import annotations class MyList(list[int]): def __add__(self, other: list[int]) -> MyList: return MyList() mypy says: ...
LoneCodeRanger's user avatar
0 votes
1 answer
30 views

Why aren't sub-union types handled properly by type guards?

In the following code, the valid function and the invalid function do exactly the same thing. Why is MyPy happy with valid, but throws an error on invalid? Isn't the TypeGuard suppose to handle that? ...
Nathan Kronenfeld's user avatar
1 vote
1 answer
37 views

Type hint for itertools.product doesn't know length of elements

I am adding type hints to an old code of mine. However, I find with a "problem" I don't know how to solve. I have a function that looks like: def f(x: tuple[tuple[int, int], ...]): ... ...
Gaussian97's user avatar
2 votes
1 answer
84 views

Is there a way to type hint pandas column names?

in a data postprocessing step I am creating a pandas DataFrame df_energy, whos columns are created according to the input data (differing each run). As column names I am using instances of a dataclass ...
Sillywumps's user avatar
0 votes
1 answer
83 views

Type alias for type of typevar and mypy

I have a type var that represents a child of specific interface BuildableChild = TypeVar("BuildableChild", bound=Buildable) The content of Buildable does not really matters, let's assume it ...
asai95's user avatar
  • 3
0 votes
2 answers
86 views

Python typing error when incrementing a dict value: 'Unsupported operand types for + ("object" and "int")'

I have this code: result = {"AAA": "a", "BBB": "b", "Count": 0} result["Count"] += 1 mypy generates this error message: Unsupported operand ...
Steve's user avatar
  • 1,282

15 30 50 per page
1
2 3 4 5
181