All Questions
26 questions
0
votes
0
answers
58
views
How to achieve Generic Return values in a python function
I have a generic function called make_request:
TParams = typing.TypeVar("TParams", bound=typing.Dict[str,str])
TBody = typing.TypeVar("TBody", bound=typing.Dict[str,str])
...
0
votes
2
answers
726
views
How to catch potentially undefined variables with pylint or mypy?
import time
if time.time() > 42:
x = 1
print(x)
My IDE (PyCharm) warns me about x potentially being undefined:
But pylint and mypy do not say anything. Is there a way to make one of them ...
2
votes
0
answers
144
views
Python Linter to catch user shadowed function names
Assume the following scenario:
def my_decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
# Code
return wrapper
def f():
# function code
return
f = ...
0
votes
0
answers
285
views
How to programmatically lint or check type hint the code string in python?
Currently I have a following format:
import pylint, mypy
# python code that I want to lint is in string
code = '
import pandas as pd
def foo(a:int, b:int)->int:
df=pd.DataFrame()
...
'
I'...
7
votes
0
answers
608
views
python: prevent discarding of the function return value
There's a common error in the code where people write something like:
if (id):
query.filter(row.id == id)
instead of
if (id):
query = query.filter(row.id == id)
The code looks "valid&...
0
votes
0
answers
438
views
class name warning for pylint type alias?
I'm using a type alias to make my code clearer:
MAGIC_TYPE = str
def f(x: Thing) -> MAGIC_TYPE
Pylint doesn't like the type alias and throws the following error:
Class name "HEADING_TYPE&...
1
vote
0
answers
908
views
Parameter optional in base class method but required in child class method
In the example below, I have a function maybe_multiply, where the input and output are optional in the base class but not in the child class. Is there a way to structure this code that avoids ...
9
votes
1
answer
8k
views
mypy gives "Incompatible default for argument" when Dict param defaults None
I understand that a Dict parameter in a Python function is best set to a default of None. However, mypy seems to disagree:
def example(self, mydict: Dict[int, str] = None):
return mydict....
3
votes
1
answer
2k
views
How to fix pylint E1134: Non-mapping value X is used in a mapping context (not-a-mapping)
pylint (2.12.2) is returning
E1134: Non-mapping value self.f_four is used in a mapping context (not-a-mapping)
For the following code
from dataclasses import dataclass
@dataclass
class One:
...
7
votes
1
answer
3k
views
How to provide type hints for argparse arguments?
I would like to get proper linting and type hints by [PyFlakes, Pylint] and mypy.
For example, in the following code, we cannot get type error for the last line.
We cannot even know if float_input ...
1
vote
1
answer
1k
views
Pylint incorrectly assumes that type is not subscriptable
I have the following code:
config = wandb.config
do_something_with_config(config['bar'], config['foo'])
For some reason, every time I access a key of config, pylint gives an unsubscriptable-object ...
1
vote
1
answer
5k
views
pylintrc configuration in visual studio code
I am currently trying to configure pylint to ensure high coding standards in a particular project.
My problem is that somehow I am not really able to configure pylint the way I would like. First I ...
0
votes
1
answer
548
views
python linting and subclass properties
I have a superclass that uses some properties from the child class.
but unless I define properties in my superclass ALSO then the linter throws errors.
what's a pythonic way to get around this?
# ...
1
vote
0
answers
48
views
Python: is it possible to infer the possible exceptions that a function can raise?
I was trying to document the possible errors that could occur as a result of a remote procedure call (RPC).
It occurred to me that it might be nice if you could do this with a little magic. Is there ...
1
vote
1
answer
586
views
How to fix mypy inferring loop variable as "object"?
I made this simple function which I want to check with mypy and
pylint. It just parses a string and converts it to the appropriate
type.
import re
from typing import Any, Callable
def ...