Skip to content

bug: TypeError when executing CTL #251

@FragmentedPacket

Description

@FragmentedPacket

Component

infrahubctl

Infrahub SDK version

1.4.0-1.7.0

Current Behavior

Whenever attempting to use InfrahubCTL commands with Python 3.9, we encounter Typing issues on execution such as executing infrahubctl version encounters the following error:

infrahubctl version
╭──────────────────────────────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ /Users/Mikhail/cloned/infrahub-sdk-python/.venv/bin/infrahubctl:6 in <module>                                                                                                                                                                      │
│                                                                                                                                                                                                                                                    │
│   3 from infrahub_sdk.ctl.cli import app                                                                                                                                                                                                           │
│   4                                                                                                                                                                                                                                                │
│   5 if __name__ == '__main__':                                                                                                                                                                                                                     │
│ ❱ 6sys.exit(app())                                                                                                                                                                                                                            │
│   7                                                                                                                                                                                                                                                │
│                                                                                                                                                                                                                                                    │
│ /Users/Mikhail/cloned/infrahub-sdk-python/.venv/lib/python3.9/site-packages/typer/main.py:340 in __call__                                                                                                                                          │
│                                                                                                                                                                                                                                                    │
│ /Users/Mikhail/cloned/infrahub-sdk-python/.venv/lib/python3.9/site-packages/typer/main.py:323 in __call__                                                                                                                                          │
│                                                                                                                                                                                                                                                    │
│ /Users/Mikhail/cloned/infrahub-sdk-python/.venv/lib/python3.9/site-packages/typer/main.py:362 in get_command                                                                                                                                       │
│                                                                                                                                                                                                                                                    │
│ /Users/Mikhail/cloned/infrahub-sdk-python/.venv/lib/python3.9/site-packages/typer/main.py:344 in get_group                                                                                                                                         │
│                                                                                                                                                                                                                                                    │
│ /Users/Mikhail/cloned/infrahub-sdk-python/.venv/lib/python3.9/site-packages/typer/main.py:481 in get_group_from_info                                                                                                                               │
│                                                                                                                                                                                                                                                    │
│ /Users/Mikhail/cloned/infrahub-sdk-python/.venv/lib/python3.9/site-packages/typer/main.py:585 in get_command_from_info                                                                                                                             │
│                                                                                                                                                                                                                                                    │
│ /Users/Mikhail/cloned/infrahub-sdk-python/.venv/lib/python3.9/site-packages/typer/main.py:556 in get_params_convertors_ctx_param_name_from_function                                                                                                │
│                                                                                                                                                                                                                                                    │
│ /Users/Mikhail/cloned/infrahub-sdk-python/.venv/lib/python3.9/site-packages/typer/utils.py:114 in get_params_from_function                                                                                                                         │
│                                                                                                                                                                                                                                                    │
│ /Users/Mikhail/cloned/infrahub-sdk-python/.venv/lib/python3.9/site-packages/typing_extensions.py:1230 in get_type_hints                                                                                                                            │
│                                                                                                                                                                                                                                                    │
│   1227 │   │     locals, respectively.                                                                                                                                                                                                             │
│   1228 │   │   """                                                                                                                                                                                                                                 │
│   1229 │   │   if hasattr(typing, "Annotated"):  # 3.9+                                                                                                                                                                                            │
│ ❱ 1230 │   │   │   hint = typing.get_type_hints(                                                                                                                                                                                                   │
│   1231 │   │   │   │   obj, globalns=globalns, localns=localns, include_extras=True                                                                                                                                                                │
│   1232 │   │   │   )                                                                                                                                                                                                                               │
│   1233 │   │   else:  # 3.8                                                                                                                                                                                                                        │
│                                                                                                                                                                                                                                                    │
│ /Users/Mikhail/.pyenv/versions/3.9.21/lib/python3.9/typing.py:1497 in get_type_hints                                                                                                                                                               │
│                                                                                                                                                                                                                                                    │
│   1494 │   │   │   │   is_argument=not isinstance(obj, types.ModuleType),                                                                                                                                                                          │
│   1495 │   │   │   │   is_class=False,                                                                                                                                                                                                             │
│   1496 │   │   │   )                                                                                                                                                                                                                               │
│ ❱ 1497 │   │   value = _eval_type(value, globalns, localns)                                                                                                                                                                                        │
│   1498 │   │   if name in defaults and defaults[name] is None:                                                                                                                                                                                     │
│   1499 │   │   │   value = Optional[value]                                                                                                                                                                                                         │
│   1500 │   │   hints[name] = value                                                                                                                                                                                                                 │
│                                                                                                                                                                                                                                                    │
│ /Users/Mikhail/.pyenv/versions/3.9.21/lib/python3.9/typing.py:292 in _eval_type                                                                                                                                                                    │
│                                                                                                                                                                                                                                                    │
│    289 │   ForwardRef.                                                                                                                                                                                                                             │
│    290 │   """                                                                                                                                                                                                                                     │
│    291if isinstance(t, ForwardRef):                                                                                                                                                                                                           │
│ ❱  292 │   │   return t._evaluate(globalns, localns, recursive_guard)                                                                                                                                                                              │
│    293if isinstance(t, (_GenericAlias, GenericAlias)):                                                                                                                                                                                        │
│    294 │   │   ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.__a                                                                                                                                                    │
│    295 │   │   if ev_args == t.__args__:                                                                                                                                                                                                           │
│                                                                                                                                                                                                                                                    │
│ /Users/Mikhail/.pyenv/versions/3.9.21/lib/python3.9/typing.py:554 in _evaluate                                                                                                                                                                     │
│                                                                                                                                                                                                                                                    │
│    551 │   │   │   │   │   sys.modules.get(self.__forward_module__, None), '__dict__', globalns                                                                                                                                                    │
│    552 │   │   │   │   )                                                                                                                                                                                                                           │
│    553 │   │   │   type_ = _type_check(                                                                                                                                                                                                            │
│ ❱  554 │   │   │   │   eval(self.__forward_code__, globalns, localns),                                                                                                                                                                             │
│    555 │   │   │   │   "Forward references must evaluate to types.",                                                                                                                                                                               │
│    556 │   │   │   │   is_argument=self.__forward_is_argument__,                                                                                                                                                                                   │
│    557 │   │   │   │   allow_special_forms=self.__forward_is_class__,                                                                                                                                                                              │
│ in <module>:1                                                                                                                                                                                                                                      │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

Expected Behavior

To be able to use Infrahubctl with Python 3.9 (or set minimum Python version to 3.10)

Steps to Reproduce

  1. Create venv with Python 3.9
  2. Install latest pip install "infrahub-sdk[ctl]" or poetry install on this repo.
  3. Execute `infrahubctl version

Additional Information

Some related issues and if you uninstall eval-type-backport package and run the infrahubctl, it'll tell you to install it.
pydantic/pydantic#7873
https://github.com/alexmojaki/eval_type_backport

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions