A blog post on choosing more specific types rather than general ones like list and dict.

You are viewing a single thread.
View all comments
3 points

Sequence now lives at collections.abc. BTW, float is not a supertype of int (issubclass(int, float) == False). Normaly, It is acceptable to use int instead of float, but speaking of variance, it is more precise to use numbers.Real:

issubclass(Integral, Real) == True
issubclass(int, Real) == True
issubclass(float, Real) == True
issubclass(complex, Real) == False
permalink
report
reply
2 points

yeah it’s an interesting case that an int can be treated as a float. I should probably update my post to mention that it’s not strictly a supertype but a special exception mentioned in python’s typehinting pep: https://peps.python.org/pep-0484/#the-numeric-tower

permalink
report
parent
reply

Python

!python@programming.dev

Create post

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events
Past

November 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
  • Pythörhead: a Python library for interacting with Lemmy
  • Plemmy: a Python package for accessing the Lemmy API
  • pylemmy pylemmy enables simple access to Lemmy’s API with Python
  • mastodon.py, a Python wrapper for the Mastodon API
Feeds

Community stats

  • 461

    Monthly active users

  • 455

    Posts

  • 2.2K

    Comments