Skip to content
Advertisement

Tag: types

How to type hint a generic numeric type in Python?

Forgive me if this question has been asked before but I could not find any related answer. Consider a function that takes a numerical type as input parameter: This works with integers, floats and complex numbers. Is there a basic type so that I can do a type hinting (of a real existing type/base class), such as: Furthermore I need

Different types of inner classes in Python 2 and Python 3

I am upgrading my project from Python 2.7 to Python 3.7 and in my code I have something like this: now type(A.B()) returns different things in the two Python versions: In Python 2.7 I get: <class ‘__main__.B’> In Python 3.7 I get: <class ‘__main__.A.B’> Can anybody explain what happens under the hood that causes this difference? Thank you very much!

How can mypy ignore a single line in a source file?

I’m using mypy in my python project for type checking. I’m also using PyYAML for reading and writing the project configuration files. Unfortunately, when using the recommended import mechanism from the PyYAML documentation this generates a spurious error in a try/except clause that attempts to import native libraries: On my system CLoader and CDumper aren’t present, which results in the

How to check if a python class or object is user defined (not a builtin)?

I need to examine a python module to find simple data as well as “user defined objects”. Here, I mean objects (or functions or classes) that are not builtin, but defined with a class/def statement or dynamically loaded/generated. Note there are similar questions, but they ask about “new style user defined classes”. I’ve seen the inspect module – I couldn’t

timedelta error with numpy.longdouble dtype

I have times with dtype numpy.longdouble and when I’m trying to use that values with timedelta function I’ve got errors. But when I convert it to numpy.float64 everything is fine. Could somebody explain that behaviour? When I’m trying to see dtypes of variables they are look the similar but not the same: Edit And it’s strange that it’s not working

Python : terminology ‘class’ VS ‘type’

Just a simple question : when should I use the term ‘class’, and when should I use the term ‘type’ in Python ? is ‘class’ only for user-defined types, and ‘type’ for built-in types ? or now that everything is a type … should I use always ‘type’ even for user-defined classes ? … ? Answer It is more or

Advertisement