Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/airflow/typing_compat.py: 79%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

14 statements  

1# 

2# Licensed to the Apache Software Foundation (ASF) under one 

3# or more contributor license agreements. See the NOTICE file 

4# distributed with this work for additional information 

5# regarding copyright ownership. The ASF licenses this file 

6# to you under the Apache License, Version 2.0 (the 

7# "License"); you may not use this file except in compliance 

8# with the License. You may obtain a copy of the License at 

9# 

10# http://www.apache.org/licenses/LICENSE-2.0 

11# 

12# Unless required by applicable law or agreed to in writing, 

13# software distributed under the License is distributed on an 

14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 

15# KIND, either express or implied. See the License for the 

16# specific language governing permissions and limitations 

17# under the License. 

18"""This module provides helper code to make type annotation within Airflow codebase easier.""" 

19 

20from __future__ import annotations 

21 

22__all__ = [ 

23 "Literal", 

24 "ParamSpec", 

25 "Protocol", 

26 "Self", 

27 "TypedDict", 

28 "TypeGuard", 

29 "runtime_checkable", 

30] 

31 

32import sys 

33from typing import Protocol, TypedDict, runtime_checkable 

34 

35# Literal from typing module has various issues in different Python versions, see: 

36# - https://typing-extensions.readthedocs.io/en/latest/#Literal 

37# - bpo-45679: https://github.com/python/cpython/pull/29334 

38# - bpo-42345: https://github.com/python/cpython/pull/23294 

39# - bpo-42345: https://github.com/python/cpython/pull/23383 

40if sys.version_info >= (3, 10, 1) or (3, 9, 8) <= sys.version_info < (3, 10): 

41 from typing import Literal 

42else: 

43 from typing_extensions import Literal # type: ignore[assignment] 

44 

45if sys.version_info >= (3, 10): 

46 from typing import ParamSpec, TypeGuard 

47else: 

48 from typing_extensions import ParamSpec, TypeGuard 

49 

50if sys.version_info >= (3, 11): 

51 from typing import Self 

52else: 

53 from typing_extensions import Self