Skip to content

add null check on pytype for type checking #3

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

Merged
merged 8 commits into from
Mar 19, 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
123 changes: 73 additions & 50 deletions .github/workflows/ci_ut_ext_base_workflow.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,84 @@
name: UT CI Run for Python Extension Base

on:
push:
branches: [ dev, master, main, release/* ]
paths:
- 'azure-functions-extension-base/**'
pull_request:
branches: [ dev, master, main, release/* ]
paths:
- 'azure-functions-extension-base/**'
push:
branches:
- dev
- main
- release/*
paths:
- 'azure-functions-extension-base/**'
pull_request:
branches:
- dev
- main
- release/*
paths:
- 'azure-functions-extension-base/**'

jobs:
build:
name: "Python Extension Base UT CI Run"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ 3.8, 3.9, "3.10", "3.11" ]
fail-fast: false
matrix:
python-version: [ 3.8, 3.9, "3.10", "3.11" ]
permissions: read-all
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
working-directory: azure-functions-extension-base
run: |
python -m pip install --upgrade pip
python -m pip install -U -e .[dev]

- name: Run Unit Tests
working-directory: azure-functions-extension-base
env:
AzureWebJobsStorage: ${{ secrets.AzureWebJobsStorage }}
run: |
python -m pytest -q --instafail --cov=. --cov-report xml --cov-branch tests

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./azure-functions-extension-base/coverage.xml
flags: unittests
name: codecov
fail_ci_if_error: false

- name: Notify dedicated teams channel
uses: jdcargile/[email protected]
if: failure()
with:
github-token: ${{ github.token }} # this will use the runner's token.
ms-teams-webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
notification-summary: "Python Extension Base UT CI Failed for Python ${{ matrix.python-version }}"
notification-color: 17a2b8
timezone: America/Denver
verbose-logging: false
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
working-directory: azure-functions-extension-base
run: |
python -m pip install --upgrade pip
python -m pip install -U -e .[dev]

- name: Run Unit Tests
working-directory: azure-functions-extension-base
env:
AzureWebJobsStorage: ${{ secrets.AzureWebJobsStorage }}
run: |
python -m pytest -q --instafail --cov=. --cov-report xml --cov-branch tests

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./azure-functions-extension-base/coverage.xml
flags: unittests
name: codecov
fail_ci_if_error: false

send-notification:
runs-on: ubuntu-latest
needs: build
if: always()
steps:
- name: Notify dedicated teams channel on failure
if: ${{ always() && needs.build.result == 'failure' }}
uses: jdcargile/[email protected]
with:
github-token: ${{ github.token }}
ms-teams-webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
notification-summary: "Python Extension Base UT CI Failed"
notification-color: FF0000
timezone: America/Denver
verbose-logging: false

- name: Notify dedicated teams channel on success
if: ${{ always() && needs.build.result == 'success' }}
uses: jdcargile/[email protected]
with:
github-token: ${{ github.token }}
ms-teams-webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
notification-summary: "Python Extension Base UT CI Passed"
notification-color: 008000
timezone: America/Denver
verbose-logging: false

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from abc import abstractmethod
from enum import Enum
import inspect
from typing import Callable

base_extension_module = __name__
Expand Down Expand Up @@ -53,7 +54,9 @@ def get_request_type(cls):

@classmethod
def check_type(cls, pytype: type) -> bool:
return cls._request_type is not None and issubclass(pytype, cls._request_type)
if pytype is not None and inspect.isclass(pytype):
return cls._request_type is not None and issubclass(pytype, cls._request_type)
return False


class ResponseTrackerMeta(type):
Expand Down Expand Up @@ -87,8 +90,10 @@ def get_response_type(cls, label):

@classmethod
def check_type(cls, pytype: type) -> bool:
return cls._response_types is not None and any(issubclass(pytype, response_type)
for response_type in cls._response_types.values())
if pytype is not None and inspect.isclass(pytype):
return cls._response_types is not None and any(issubclass(pytype, response_type)
for response_type in cls._response_types.values())
return False

class WebApp(metaclass=ModuleTrackerMeta):
@abstractmethod
Expand Down