{"id":28529182,"url":"https://github.com/sirkonst/type_comparable","last_synced_at":"2025-07-06T23:30:33.698Z","repository":{"id":62585902,"uuid":"118948022","full_name":"sirkonst/type_comparable","owner":"sirkonst","description":"Helper for checking variable equivalence by type. Useful for tests.","archived":false,"fork":false,"pushed_at":"2025-01-19T15:37:28.000Z","size":25,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-09T13:57:11.524Z","etag":null,"topics":["pytest","pytest-plugin","test","testing","type","types","typing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sirkonst.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-25T17:57:31.000Z","updated_at":"2025-01-19T15:36:51.000Z","dependencies_parsed_at":"2025-01-19T16:28:05.439Z","dependency_job_id":"c2e42cc9-7b3d-46be-91d1-8c9e0267f73a","html_url":"https://github.com/sirkonst/type_comparable","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/sirkonst/type_comparable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sirkonst%2Ftype_comparable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sirkonst%2Ftype_comparable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sirkonst%2Ftype_comparable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sirkonst%2Ftype_comparable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sirkonst","download_url":"https://codeload.github.com/sirkonst/type_comparable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sirkonst%2Ftype_comparable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263988150,"owners_count":23540128,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pytest","pytest-plugin","test","testing","type","types","typing"],"created_at":"2025-06-09T13:42:02.311Z","updated_at":"2025-07-06T23:30:33.691Z","avatar_url":"https://github.com/sirkonst.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"About\n=====\n\nModule allows to compare variables not only by value but by type too. \n\nQuick example:\n\n.. code-block:: python\n\n    from typing import Any\n\n    from type_comparable import make_type_comparable\n\n    response = {\n        'id': 144233,\n        'date_create': '2020-01-25T17:31:33.910803',\n        'important_data': 'important data',\n        'other_data': 'other data',\n        'inner_data': {\n            'field a': 'value a',\n            'field d': 'value b'\n        },\n        'line': [1, 'some text', 3]\n    }\n    assert make_type_comparable(response) == {\n        'id': int,  # \u003c-- will compare by type int\n        'date_create': str, # \u003c -- will compare by type str\n        'important_data': 'important data',  # \u003c-- exact match as is\n        'other_data': Any, # \u003c-- allow any data,\n        'inner_date': {  # \u003c-- also work with nested dictionaries\n            'field a': str,\n            'field b': 'value b'\n        }\n        'line': [int, Any, 3]  # \u003c- check elements in array\n    }\n\n    # if you don't want wrap left variable (response) if can wrap right:\n    assert response == make_type_comparable(...)\n\nVery useful for tests by pytest.\n\n\nSupport types\n=============\n\nComparable types (which can be passed to `make_type_comparable()`):\n\n- `int`\n- `bool`\n- `str`\n- `list`\n- `dict`\n- other\n\nTypes for comparison:\n\n- all python builtin (`int`, `str`, `bool`, `list`, `dict`, etc.)\n- `object` and `typing.Any` - mean any type but not `None`\n- `typing.Optional` - mean any type and `None`. `Optional[int]` now not supported\n\nAlso you can try to use with your custom types but without guaranteed (verify \nmanually before use in product)\n\n\nKnow issues\n===========\n\nWrapped `None` is not `None` :-(\n\n.. code-block:: python\n\n    \u003e\u003e make_type_comparable(None) is None\n    False\n\n    # use equal\n    \u003e\u003e make_type_comparable(None) == None\n    True\n\n\nInstall\n=======\n\nFrom PyPi:\n\n.. code-block:: bash\n\n    $ pip install type_comparable\n\n\nFrom local:\n\n.. code-block:: bash\n\n    # update setuptools\n    $ pip install 'setuptools \u003e= 30.4'\n    # do install\n    $ make install\n    # or\n    $ pip install .\n\n\nDevelopment\n===========\n\nPrepare and activate virtual environment like:\n\n.. code-block:: bash\n\n    $ python3 -m venv .env\n    # for bash\n    $ source .env/bin/activate\n    # for fish\n    $ . .env/bin/activate.fish\n    \nUpdate pre-install dependencies:\n\n.. code-block:: bash\n\n    $ pip install 'setuptools \u003e= 30.4'\n\n\nInstall:\n\n.. code-block:: bash\n\n    $ make install_dev\n    # or\n    $ pip install --editable .[develop]\n\nRun tests:\n\n.. code-block:: bash\n\n    $ make test\n    # or \n    $ pytest tests/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirkonst%2Ftype_comparable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsirkonst%2Ftype_comparable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirkonst%2Ftype_comparable/lists"}