{"id":4719,"library":"pysubtypes","title":"Python Subtypes","description":"pysubtypes is a Python library that provides subclasses for common Python built-in types (like Str, Int, List, Dict) with additional functionality and convenience methods. It aims to enhance native types with common utility methods and properties. The library maintains a frequent release cadence, primarily with patch versions, and is currently at version 0.3.18.","status":"active","version":"0.3.18","language":"en","source_language":"en","source_url":"https://github.com/matthewgdv/subtypes","tags":["types","subclassing","utilities","data structures","enhancements"],"install":[{"cmd":"pip install pysubtypes","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for execution.","package":"python","optional":false}],"imports":[{"symbol":"Str","correct":"from subtypes import Str"},{"symbol":"Int","correct":"from subtypes import Int"},{"symbol":"List","correct":"from subtypes import List"},{"symbol":"Dict","correct":"from subtypes import Dict"},{"symbol":"AnyString","correct":"from subtypes import AnyString"}],"quickstart":{"code":"from subtypes import Str, List\n\n# Enhanced string functionality\nmy_string = Str(\"Hello world\")\nformatted_string = my_string(\"from the other side\")\nprint(f\"Formatted string: {formatted_string}\")\nprint(f\"Title case: {my_string.title}\")\n\n# Enhanced list functionality\nmy_list = List([1, 2, 3])\nmy_list.append_unique(2)\nmy_list.append_unique(4)\nprint(f\"Unique appends: {my_list}\")\n\n# Accessing underlying native type\nprint(f\"Native list: {my_list.native}\")","lang":"python","description":"This example demonstrates importing and using the `Str` and `List` subtypes. It showcases method chaining, enhanced string formatting, and unique list appends. The `.native` property allows access to the underlying built-in Python type."},"warnings":[{"fix":"Profile critical sections of code if performance is a concern, and test against expected behaviors. Use the `.native` property to revert to the built-in type if specific native behavior is required.","message":"When subclassing built-in types, be aware that not all native C-level optimizations and behaviors of the original types may be fully preserved. While `pysubtypes` aims for compatibility, some subtle differences in performance or memory usage might occur.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the source code on GitHub for specific type behaviors if ambiguity arises. Leverage the `.native` property when interacting with external libraries or functions that expect standard Python types to avoid unexpected method calls.","message":"The library heavily relies on implicit `__call__` and other magic methods for its convenience features. This can sometimes lead to unexpected behavior if you're not familiar with how these methods are overloaded, especially when chaining operations or passing `pysubtypes` instances to functions expecting strict built-in types.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For operations where raw performance is paramount, consider using the native Python built-in types or converting `pysubtypes` instances to their native counterparts using the `.native` property before entering performance-sensitive loops.","message":"Direct instantiation of built-in types might be preferred in performance-critical loops due to the overhead introduced by subclassing and additional method lookups. The utility of `pysubtypes` shines in code readability and expressiveness over raw speed for basic operations.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}