Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix autocompletion support for VSCode #58

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ jobs:
strategy:
fail-fast: false
matrix:
k8s: [ 1.23, 1.27 ]
k8s: [ '1.23', '1.27' ]
name: E2E test in K8s ${{ matrix.k8s }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
14 changes: 13 additions & 1 deletion lightkube/core/dataclasses_dict.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import typing
from typing import get_type_hints
from typing import Union
from datetime import datetime
import dataclasses as dc

Expand Down Expand Up @@ -51,6 +51,18 @@ def nohop(x, kw):
def is_dataclass_json(cls):
return dc.is_dataclass(cls) and issubclass(cls, DataclassDictMixIn)

NoneType = type(None)

def _remove_optional(tp):
if get_origin(tp) is Union:
args = get_args(tp)
if args[1] is NoneType:
return args[0]
return tp

def get_type_hints(cl):
types = typing.get_type_hints(cl)
return {k: _remove_optional(v) for k, v in types.items()}

def extract_types(cls, is_to=True):
func_name = "to_json_type" if is_to else "from_json_type"
Expand Down
8 changes: 8 additions & 0 deletions lightkube/core/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
This module exposes dependencies used by lightkube-models

These dependencies are here because we may decide to replace dataclasses with something else in the future
"""
from dataclasses import dataclass, field

from .dataclasses_dict import DataclassDictMixIn as DictMixin
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='lightkube',
version="0.15.0",
version="0.15.1",
description='Lightweight kubernetes client library',
long_description=Path("README.md").read_text(),
long_description_content_type="text/markdown",
Expand Down
Loading